Skip to content

Commit

Permalink
solved ex 1
Browse files Browse the repository at this point in the history
  • Loading branch information
javlintor committed Nov 14, 2023
1 parent 44f5f20 commit c0cf449
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions notebooks/introduction-python/exercises.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,93 @@
":::"
]
},
{
"cell_type": "code",
"source": [
"d = {\"a\": \"foo\", \"b\": \"bar\"}\n",
"for k in d:\n",
" print(k)"
],
"metadata": {
"id": "j0bQ92RpJxJD",
"outputId": "2da549f3-8e2c-4b63-b9f0-9112880bc556",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"a\n",
"b\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"def merge(*args):\n",
" merge_dict = {}\n",
" for dictionary in args:\n",
" # iterar sobre las claves de dictionary\n",
" for key in dictionary:\n",
" if key in merge_dict:\n",
" merge_dict[key].append(dictionary[key])\n",
" else:\n",
" merge_dict[key] = [dictionary[key]]\n",
" return merge_dict\n"
],
"metadata": {
"id": "3JgYpi4XIq-p"
},
"execution_count": 5,
"outputs": []
},
{
"cell_type": "code",
"source": [
"dict1 = {\n",
" \"foo\": 1,\n",
" \"bar\": [3, 4],\n",
" \"baz\": None\n",
"}\n",
"\n",
"dict2 = {\n",
" \"foo\": \"Hello world\",\n",
" 5: \"five\"\n",
"}\n",
"\n",
"dict3 = {\n",
" \"bar\": \"yes\"\n",
"}\n",
"\n",
"merge(dict1, dict2, dict3)"
],
"metadata": {
"id": "31pMhyRxIlXk",
"outputId": "cb4dd71e-316c-43ed-8c13-b418e82f4735",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'foo': [1, 'Hello world'], 'bar': [[3, 4], 'yes'], 'baz': [None], 5: ['five']}"
]
},
"metadata": {},
"execution_count": 6
}
]
},
{
"cell_type": "markdown",
"source": [
Expand Down

0 comments on commit c0cf449

Please sign in to comment.