Python Toolbox
Hugo Bowne-Anderson
Data Scientist at DataCamp
employees = ['Nick', 'Lore', 'Hugo']
for employee in employees: print(employee)
Nick
Lore
Hugo
for letter in 'DataCamp':
print(letter)
D
a
t
a
C
a
m
p
for i in range(4):
print(i)
0
1
2
3
iter()
methoditer()
to an iterable creates an iteratornext()
word = 'Da' it = iter(word)
next(it)
'D'
next(it)
'a'
next(it)
StopIteration Traceback (most recent call last)
<ipython-input-11-2cdb14c0d4d6> in <module>()
-> 1 next(it)
StopIteration:
word = 'Data' it = iter(word)
print(*it)
D a t a
print(*it)
pythonistas = {'hugo': 'bowne-anderson', 'francis': 'castro'}
for key, value in pythonistas.items(): print(key, value)
francis castro
hugo bowne-anderson
file = open('file.txt') it = iter(file)
print(next(it))
This is the first line.
print(next(it))
This is the second line.
Python Toolbox