Skip to content

Commit

Permalink
other data structures
Browse files Browse the repository at this point in the history
  • Loading branch information
javlintor committed Nov 6, 2023
1 parent 3edde33 commit 94f1949
Showing 1 changed file with 114 additions and 18 deletions.
132 changes: 114 additions & 18 deletions notebooks/introduction-python/other-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@
"```"
]
},
{
"cell_type": "markdown",
"source": [
"El segundo argumento de la funión `isinstance` puede ser una tupla de tipos, de modo que devolverá `True` si el objeto es de alguno de los tipos que forman la tupla."
],
"metadata": {
"id": "MDLXPdiRM3oL"
}
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -740,20 +749,6 @@
":::"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "afh-nIRFDC74"
},
"source": [
":::{exercise}\n",
":label: other-data-structures-slices-4\n",
"\n",
"Dada una secuencia `seq` y un índice negativo `neg_index`, escribe la fórmula que nos daría el índice positivo correspondiente.\n",
"\n",
":::"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -1135,7 +1130,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {
"id": "_1UwieAN3iOY"
},
Expand Down Expand Up @@ -1283,6 +1278,108 @@
"list(example_dict.items())"
]
},
{
"cell_type": "markdown",
"source": [
"Los diccionarios son objetos **iterables**"
],
"metadata": {
"id": "_HlIr3SKPzZn"
}
},
{
"cell_type": "code",
"source": [
"x, s = {\"a\": \"foo\", 1: \"bar\"}"
],
"metadata": {
"id": "bUtW1kN1QI7R"
},
"execution_count": 5,
"outputs": []
},
{
"cell_type": "code",
"source": [
"x"
],
"metadata": {
"id": "00SkGYQkQVa1",
"outputId": "6cdd42a9-ee83-46fa-a342-82ad9a8fc8f5",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 36
}
},
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'a'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 6
}
]
},
{
"cell_type": "code",
"source": [
"s"
],
"metadata": {
"id": "Yp0TFrp1QXvD",
"outputId": "cbca2368-9c9c-4ec7-9106-2fd8bfbd4179",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"1"
]
},
"metadata": {},
"execution_count": 7
}
]
},
{
"cell_type": "code",
"source": [
"for k in example_dict:\n",
" print(k)"
],
"metadata": {
"id": "JyLAVsNzQfOy",
"outputId": "edd2cff1-b22d-49f0-89f1-65e84dd272b7",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"key1\n",
"key2\n",
"key3\n"
]
}
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -1465,7 +1562,7 @@
"source": [
"Los **generadores** nos permiten generar en forma de promesa un número arbitrario de items sin necesidad de guardarlos en memoria. Se trata de un objeto iterable, pero que genera cada uno de sus miembros en orden cuando las iteraciones lo vayan requiriendo. Ya hemos visto un ejemplo de generador cuando hemos utilizado la función `range`. Es bastante común contruir listas, tuplas o conjuntos a partir de un generador.\n",
"\n",
"La sintaxis para crear un generador es la siguiente\n",
"Una sintaxis disponible para crear un generador es la siguiente\n",
"\n",
"```\n",
"(<expression> for <var> in <iterable> if <condition>)\n",
Expand Down Expand Up @@ -1949,8 +2046,7 @@
],
"metadata": {
"colab": {
"provenance": [],
"toc_visible": true
"provenance": []
},
"kernelspec": {
"display_name": "Python 3.9.1 64-bit",
Expand Down

0 comments on commit 94f1949

Please sign in to comment.