Skip to content

Commit 744f25a

Browse files
committed
Adding List operations
1 parent ef43ffb commit 744f25a

File tree

1 file changed

+113
-2
lines changed

1 file changed

+113
-2
lines changed

Chapter02/Exercise27/Exercise27.ipynb

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
{
4545
"cell_type": "code",
46-
"execution_count": 4,
46+
"execution_count": 3,
4747
"metadata": {},
4848
"outputs": [
4949
{
@@ -59,6 +59,117 @@
5959
"print(shopping)"
6060
]
6161
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": 4,
65+
"metadata": {},
66+
"outputs": [
67+
{
68+
"name": "stdout",
69+
"output_type": "stream",
70+
"text": [
71+
"['bread', 'milk', 'ham', 'eggs', 'apple', 'coffee', 'orange']\n"
72+
]
73+
}
74+
],
75+
"source": [
76+
"new_shopping = ['coffee', 'orange']\n",
77+
"shopping.extend(new_shopping) \n",
78+
"print(shopping)"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": 5,
84+
"metadata": {},
85+
"outputs": [
86+
{
87+
"name": "stdout",
88+
"output_type": "stream",
89+
"text": [
90+
"['bread', 'milk', 'eggs', 'apple', 'coffee', 'orange']\n"
91+
]
92+
}
93+
],
94+
"source": [
95+
"shopping.remove('ham')\n",
96+
"print(shopping)"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": 6,
102+
"metadata": {},
103+
"outputs": [
104+
{
105+
"name": "stdout",
106+
"output_type": "stream",
107+
"text": [
108+
"['bread', 'milk', 'apple', 'coffee', 'orange']\n"
109+
]
110+
}
111+
],
112+
"source": [
113+
"shopping.pop(2)\n",
114+
"print(shopping)"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": 7,
120+
"metadata": {},
121+
"outputs": [
122+
{
123+
"name": "stdout",
124+
"output_type": "stream",
125+
"text": [
126+
"['apple', 'bread', 'coffee', 'milk', 'orange']\n"
127+
]
128+
}
129+
],
130+
"source": [
131+
"shopping.sort()\n",
132+
"print(shopping)"
133+
]
134+
},
135+
{
136+
"cell_type": "code",
137+
"execution_count": 8,
138+
"metadata": {},
139+
"outputs": [
140+
{
141+
"name": "stdout",
142+
"output_type": "stream",
143+
"text": [
144+
"['orange', 'milk', 'coffee', 'bread', 'apple']\n"
145+
]
146+
}
147+
],
148+
"source": [
149+
"shopping.sort(reverse = True)\n",
150+
"print(shopping)"
151+
]
152+
},
153+
{
154+
"cell_type": "code",
155+
"execution_count": 9,
156+
"metadata": {},
157+
"outputs": [
158+
{
159+
"data": {
160+
"text/plain": [
161+
"2"
162+
]
163+
},
164+
"execution_count": 9,
165+
"metadata": {},
166+
"output_type": "execute_result"
167+
}
168+
],
169+
"source": [
170+
"shopping.index('coffee')"
171+
]
172+
},
62173
{
63174
"cell_type": "code",
64175
"execution_count": null,
@@ -83,7 +194,7 @@
83194
"name": "python",
84195
"nbconvert_exporter": "python",
85196
"pygments_lexer": "ipython3",
86-
"version": "3.7.3"
197+
"version": "3.7.4"
87198
}
88199
},
89200
"nbformat": 4,

0 commit comments

Comments
 (0)