Skip to content

Commit c8b07a8

Browse files
committed
added stuff for the classwork
1 parent 4c045d1 commit c8b07a8

6 files changed

Lines changed: 13131 additions & 1 deletion

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
What happens when you delete from a list while looping through it?
5+
"""
6+
7+
a_list = list(range(10))
8+
print("the original", a_list)
9+
# loop to remove almost everything...
10+
for item in a_list[:]:
11+
if item: # is it an nonzero number?
12+
a_list.remove(item)
13+
print("after removing some", a_list)
14+
15+
# is that what you expected?
16+
17+
# what about adding stuff?
18+
a_list = list(range(10))
19+
new_list = []
20+
for item in a_list:
21+
new_list.append(item)
22+
if item % 2: # duplicate odd numbers
23+
new_list.append(item)
24+
25+
print("after adding odd numbers", new_list)
26+
27+
#
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
Marlon M Estrada
3+

‎students/Chris/session04/get_langs.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
infile = "students.txt"
88

99
all_langs = []
10-
with open(infile) as students:
10+
with open(infile, 'r') as students:
1111
students.readline()
1212
for line in students:
1313
line = line.strip()

0 commit comments

Comments
 (0)