Commit 2e94e286 authored by geobumac's avatar geobumac

ejecricios 2

parent a608acc9
...@@ -310,11 +310,22 @@ ...@@ -310,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])"
] ]
}, },
{ {
...@@ -327,11 +338,24 @@ ...@@ -327,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"
] ]
}, },
{ {
...@@ -344,12 +368,65 @@ ...@@ -344,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]"
] ]
}, },
{ {
...@@ -362,11 +439,23 @@ ...@@ -362,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))"
] ]
}, },
{ {
...@@ -379,11 +468,24 @@ ...@@ -379,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)"
] ]
}, },
{ {
...@@ -415,6 +517,30 @@ ...@@ -415,6 +517,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": {},
......
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