Skip to content

Commit

Permalink
Quiz UTA-DataScience#1 Submission
Browse files Browse the repository at this point in the history
  • Loading branch information
HalaMuhiar authored Feb 16, 2024
1 parent 909b438 commit 72f7222
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions Labs/Lab.2/Quiz #1 Hala Muhiar 1001900490.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Quick Quiz\n",
"\n",
"Can you rewrite `create_new_args` as a two lines of code using functional programming, list comprehensions, and shortcuts? How about a single line?"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"def create_new_args_0(*args):\n",
" max_len = max(map(len,\n",
" filter(lambda x: isinstance(x,list),\n",
" args)))\n",
"\n",
" # Rewrite this section:\n",
" new_args = [[a]*max_len if isinstance(a, list) else a if len(a)==max_len else None for a in args]\n",
"\n",
" return new_args"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[[[1, 2], [3, 4], 5], [[1, 2], [3, 4], 5], [[1, 2], [3, 4], 5]]]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"create_new_args_0([[1,2],[3,4],5])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[[[1, 2], [3, 4, 5], 5], [[1, 2], [3, 4, 5], 5], [[1, 2], [3, 4, 5], 5]]]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"create_new_args_0([[1,2],[3,4,5],5])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit 72f7222

Please sign in to comment.