-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHead_First_cap01.py
More file actions
89 lines (61 loc) · 1.94 KB
/
Copy pathHead_First_cap01.py
File metadata and controls
89 lines (61 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# coding: utf-8
Head First Python
Cap. 01:
# In[3]:
#Lista de filmes
movies = ["The Holy Grail", "The Life of Brian", "The Meaning of Life"]
print(movies)
print(movies[1])
# In[8]:
#pág 10
cast = ["Cleese", "Palin", "Jones", "Idle"]
print(cast)
print(len(cast))
print(cast[1])
cast.append("Gilliam")
print(cast)
cast.pop()
print(cast)
cast.extend(["Gilliam", "Chapman"])
print(cast)
cast.remove("Chapman")
cast.insert(0, "Chapman")
print(cast)
# In[11]:
#pág 15, for:
fav_movies = ["The Holy Gray", "The Life of Brian"]
for each_flick in fav_movies:
print(each_flick)
#while
count = 0
while count < len(fav_movies):
print(fav_movies[count])
count = count + 1
# In[18]:
#pág 19
movies = ["The Holy Gray", 1975, "Terry Jones & Terry Gilliam", 91, ["Graham Chapman", ["Michael Palin", "John Cleese", "Terry Gilliam", "Eric Idle", "Terry Jones"]]]
for each_item in movies:
if isinstance(each_item, list):
for nested_item in each_item:
if isinstance(nested_item, list):
for deeper_item in nested_item:
print(deeper_item)
else:
print(nested_item)
else:
print(each_item)
# In[20]:
#pág. 30 function: melhorada com código da pág. 58
level = 0
movies = ["The Holy Gray", 1975, "Terry Jones & Terry Gilliam", 91, ["Graham Chapman", ["Michael Palin", "John Cleese", "Terry Gilliam", "Eric Idle", "Terry Jones"]]]
def print_lol(the_list, indent=False, level=0): #definindo level = 0 tornamos esse argumento opcional, e inicializamos com indent = False para que o padrão seja não ativo
for each_item in the_list:
if isinstance(each_item, list):
print_lol(each_item, True, level+1)
else:
if indent:
for tab_stop in range(level):
print ("\t", end='')
print(each_item)
print_lol(movies, True, 0) #para ativar fornecemos o parametro true
# In[ ]: