Skip to content

[Felix] lab-list-comprehension #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 146 additions & 18 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -30,7 +30,10 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"new_list = [i for i in range(1,51)]\n",
"print(new_list)"
]
},
{
"cell_type": "markdown",
Expand All @@ -44,7 +47,10 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"new_list = [i for i in range(2,201,2)]\n",
"print(new_list)"
]
},
{
"cell_type": "markdown",
Expand All @@ -55,7 +61,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -76,7 +82,15 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"new_list = [for i in a for j in i]\n",
"\n",
"for i in a:\n",
" for j in i:\n",
" new_list.append(j)\n",
" \n",
"print(new_list)"
]
},
{
"cell_type": "markdown",
Expand All @@ -90,7 +104,11 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"list_2 = [j for i in a for j in i if j >= 0.5]\n",
" \n",
"print(list2)"
]
},
{
"cell_type": "markdown",
Expand All @@ -101,7 +119,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -123,10 +141,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.55867166, 0.06210792, 0.08147297, 0.82579068, 0.91512478, 0.06833034, 0.05440634, 0.65857693, 0.30296619, 0.06769833, 0.96031863, 0.51293743, 0.09143215, 0.71893382, 0.45850679, 0.58256464, 0.59005654, 0.56266457, 0.71600294, 0.87392666, 0.11434044, 0.8694668, 0.65669313, 0.10708681, 0.07529684, 0.46470767, 0.47984544, 0.65368638, 0.14901286, 0.23760688]\n"
]
}
],
"source": [
"list0 = [list3 for list1 in b for list2 in list1 for list3 in list2]\n",
"\n",
"print(list0)"
]
},
{
"cell_type": "markdown",
Expand All @@ -137,10 +167,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.08147297, 0.06833034, 0.30296619, 0.45850679, 0.11434044, 0.10708681, 0.47984544, 0.23760688]\n"
]
}
],
"source": [
"list_1 = [subarray[-1] for array in b for subarray in array if subarray[-1] <= 0.5]\n",
"\n",
"print(list_1)\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -151,10 +193,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CSV files in the directory:\n",
"['sample_file_0.csv', 'sample_file_1.csv', 'sample_file_2.csv', 'sample_file_3.csv', 'sample_file_4.csv', 'sample_file_5.csv', 'sample_file_6.csv', 'sample_file_7.csv', 'sample_file_8.csv', 'sample_file_9.csv']\n"
]
}
],
"source": [
"import os\n",
"\n",
"directory_path = 'C://Users//Felix//Documents//Ironhack//lab-list-comprehension//data'\n",
"\n",
"csv_files = [file for file in os.listdir(directory_path) if file.endswith('.csv')]\n",
"\n",
"print(\"CSV files in the directory:\")\n",
"print(csv_files)\n"
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -189,11 +249,79 @@
"**Advanced**\n",
"- [Queue time counter](https://www.codewars.com/kata/queue-time-counter)"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[-1, -2, -3, 4, 5]\n"
]
}
],
"source": [
"list_=[1,2,3,-4,-5]\n",
"\n",
"inverted_number = [-num for num in list_]\n",
"\n",
"print(inverted_number)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 88,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"9\n"
]
}
],
"source": [
"sum_1 = [1, 2 ,2]\n",
"\n",
"result = sum(a ** 2 for a in sum_1)\n",
"\n",
"print(result)"
]
},
{
"cell_type": "code",
"execution_count": 100,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['5', '4', '3', '2', '2', '4', '3', '6']\n"
]
}
],
"source": [
"return_array = 54322436\n",
"\n",
"new_array = []\n",
"\n",
"for num in str(return_array):\n",
" new_array.append(num)\n",
" \n",
"print(new_array)\n",
" \n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -207,7 +335,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.11.3"
}
},
"nbformat": 4,
Expand Down