Commit abb0d2f2 authored by geobumac's avatar geobumac

ejercicios 2

parent 2e94e286
...@@ -173,22 +173,23 @@ ...@@ -173,22 +173,23 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[4, 4, 256, 46656, 16777216]" "[27, 46656, 387420489]"
] ]
}, },
"execution_count": 41, "execution_count": 4,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
], ],
"source": [ "source": [
"list(map(lambda i: i**i, filter(lambda i: i%2==0, old_list)))" "old_list = [1,2,2,3,4,5,6,7,7,8,9]\n",
"list(map(lambda i: i**i, filter(lambda i: i%3==0, old_list)))"
] ]
}, },
{ {
...@@ -309,11 +310,22 @@ ...@@ -309,11 +310,22 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 67, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"pares [0, 2, 4, 6, 8]\n",
"impares [1, 3, 5, 7, 9]\n"
]
}
],
"source": [ "source": [
"a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" "a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
"print(\"pares \", [i for i in a if i%2==0])\n",
"print(\"impares \", [i for i in a if i%2!=0])"
] ]
}, },
{ {
...@@ -326,11 +338,24 @@ ...@@ -326,11 +338,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 69, "execution_count": 25,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"[[0, 'apple'], [1, 'banana'], [2, 'grapes'], [3, 'pear']]"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"my_list = ['apple', 'banana', 'grapes', 'pear']\n" "my_list = ['apple', 'banana', 'grapes', 'pear']\n",
"[[i,my_list[i]] for i in range(0,len(my_list))]\n",
"\n"
] ]
}, },
{ {
...@@ -343,12 +368,65 @@ ...@@ -343,12 +368,65 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 72, "execution_count": 27,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"[[0, 'a'],\n",
" [0, 'b'],\n",
" [0, 'c'],\n",
" [0, 'd'],\n",
" [0, 'e'],\n",
" [0, 'f'],\n",
" [1, 'a'],\n",
" [1, 'b'],\n",
" [1, 'c'],\n",
" [1, 'd'],\n",
" [1, 'e'],\n",
" [1, 'f'],\n",
" [2, 'a'],\n",
" [2, 'b'],\n",
" [2, 'c'],\n",
" [2, 'd'],\n",
" [2, 'e'],\n",
" [2, 'f'],\n",
" [3, 'a'],\n",
" [3, 'b'],\n",
" [3, 'c'],\n",
" [3, 'd'],\n",
" [3, 'e'],\n",
" [3, 'f'],\n",
" [4, 'a'],\n",
" [4, 'b'],\n",
" [4, 'c'],\n",
" [4, 'd'],\n",
" [4, 'e'],\n",
" [4, 'f'],\n",
" [5, 'a'],\n",
" [5, 'b'],\n",
" [5, 'c'],\n",
" [5, 'd'],\n",
" [5, 'e'],\n",
" [5, 'f'],\n",
" [6, 'a'],\n",
" [6, 'b'],\n",
" [6, 'c'],\n",
" [6, 'd'],\n",
" [6, 'e'],\n",
" [6, 'f']]"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"a = [0,1,2,3,4,5,6]\n", "a = [0,1,2,3,4,5,6]\n",
"b = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"]" "b = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\"]\n",
"[[i,n] for i in a for n in b]"
] ]
}, },
{ {
...@@ -361,11 +439,23 @@ ...@@ -361,11 +439,23 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 74, "execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"[22, 54, 62]"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"a=[5, 7, 22, 97, 54, 62, 77, 23, 73, 61]" "a=[5, 7, 22, 97, 54, 62, 77, 23, 73, 61]\n",
"list(filter(lambda x:x%2 == 0, a))"
] ]
}, },
{ {
...@@ -378,11 +468,24 @@ ...@@ -378,11 +468,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 76, "execution_count": 34,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"193"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"a = [5, 8, 10, 20, 50, 100] " "from functools import reduce\n",
"a = [5, 8, 10, 20, 50, 100] \n",
"reduce((lambda x, y: x + y), a)"
] ]
}, },
{ {
...@@ -395,13 +498,26 @@ ...@@ -395,13 +498,26 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 78, "execution_count": 39,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"[35, 45, 55, 65]"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"a = [5, 10, 15, 20]\n", "a = [5, 10, 15, 20]\n",
" \n", " \n",
"b = [30, 35, 40, 45]" "b = [30, 35, 40, 45]\n",
"\n",
"list(map(lambda x,y: x+y, a,b))"
] ]
}, },
{ {
...@@ -414,6 +530,30 @@ ...@@ -414,6 +530,30 @@
"[Wikipedia](https://es.wikipedia.org/wiki/Terna_pitag%C3%B3rica): Una terna pitagórica es un conjunto ordenado de tres números enteros positivos a, b, c, y son solución de la ecuación diofantina cuadrática $a^{2}+b^{2}=c^{2}$.\n" "[Wikipedia](https://es.wikipedia.org/wiki/Terna_pitag%C3%B3rica): Una terna pitagórica es un conjunto ordenado de tres números enteros positivos a, b, c, y son solución de la ecuación diofantina cuadrática $a^{2}+b^{2}=c^{2}$.\n"
] ]
}, },
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n"
]
}
],
"source": [
"def pitagoricas(n):\n",
" num = 0\n",
" while num <= n:\n",
" yield []\n",
" num += 1\n",
"\n",
"pit = pitagoricas(10)\n",
"print(next(pit))"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
...@@ -428,7 +568,7 @@ ...@@ -428,7 +568,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = [\"a\", \"b\", \"c\"]" "a = [\"a\", \"b\", \"c\"]\n"
] ]
}, },
{ {
......
...@@ -498,13 +498,26 @@ ...@@ -498,13 +498,26 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 78, "execution_count": 39,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"[35, 45, 55, 65]"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"a = [5, 10, 15, 20]\n", "a = [5, 10, 15, 20]\n",
" \n", " \n",
"b = [30, 35, 40, 45]" "b = [30, 35, 40, 45]\n",
"\n",
"list(map(lambda x,y: x+y, a,b))"
] ]
}, },
{ {
...@@ -555,7 +568,7 @@ ...@@ -555,7 +568,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"a = [\"a\", \"b\", \"c\"]" "a = [\"a\", \"b\", \"c\"]\n"
] ]
}, },
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment