Skip to content
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
69 changes: 57 additions & 12 deletions lab-python-list-comprehension.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,28 @@
"execution_count": null,
"id": "21625526-3fae-4c55-bab5-f91940070681",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['Open', 'Open', 'Senior', 'Open', 'Open', 'Senior']"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code goes here"
"# your code goes here\n",
"\n",
"prospects = [[18, 20], [45, 2], [61, 12], [37, 6], [21, 21], [78, 9]]\n",
"\n",
"cat_member = [\"Senior\" if p[0] >= 55 and p[1] > 7 else \"Open\" for p in prospects]\n",
"cat_member\n",
"\n",
"#senior member 55 y and handicap <7\n",
"#mejor jugador - valor de handicap"
]
},
{
Expand All @@ -100,7 +119,11 @@
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
"# your code goes here\n",
"def suma_multiples(n):\n",
" if n < 0:\n",
" return 0\n",
" return sum([x for x in range(n) if x % 3 == 0 or x % 5 == 0])"
]
},
{
Expand Down Expand Up @@ -132,7 +155,11 @@
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
"# your code goes here\n",
"\n",
"def new_list(n):\n",
" separados =[int(x) for x in str(n)]\n",
" return separados"
]
},
{
Expand Down Expand Up @@ -160,7 +187,10 @@
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
"# your code goes here\n",
"def inversa(num):\n",
" result = [-x for x in num]\n",
" return result"
]
},
{
Expand Down Expand Up @@ -198,7 +228,9 @@
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
"# your code goes here\n",
"\n",
"new_dict = {key:key**2 for key in range(1,16)}"
]
},
{
Expand All @@ -225,7 +257,10 @@
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
"# your code goes here\n",
"def nueva_lista(lista1, lista2):\n",
" new_list = [(x,y) for x in lista1 for y in lista2]\n",
" return new_list"
]
},
{
Expand All @@ -251,7 +286,10 @@
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
"# your code goes here\n",
"def lista_dic(diccionario):\n",
" new_list = [(k, v) for k, values in diccionario.items() for v in values]\n",
" return new_list"
]
},
{
Expand Down Expand Up @@ -286,7 +324,11 @@
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
"# your code goes here\n",
"\n",
"def tuplas_v(tupla):\n",
" new_list = [(num1, num2) for lista1, lista2 in tupla for num1 in lista1 for num2 in lista2]\n",
" return new_list"
]
},
{
Expand All @@ -313,13 +355,16 @@
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
"# your code goes here\n",
"def nuevo_diccionario(list_string):\n",
" new_set = {(a, b) for a in list_string[0] for b in list_string[1]}\n",
" return new_set"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -333,7 +378,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down