Skip to content

Instantly share code, notes, and snippets.

@elleryq
Last active January 28, 2019 10:10
Show Gist options
  • Save elleryq/5910ab4b12daf8cb79c3477df3ddb19f to your computer and use it in GitHub Desktop.
Save elleryq/5910ab4b12daf8cb79c3477df3ddb19f to your computer and use it in GitHub Desktop.
Rewrite using while
#!/usr/bin/python3
players = [
['james', 202],
['curry', 193],
['durant', 205],
['jordan', 199],
['david', 211]]
players_iter = iter(players)
player = next(players_iter, None)
while player:
if player[1] >= 200:
print(player)
player = next(players_iter, None)
####
# Another
####
#!/usr/bin/python3
#players = [
# ['james', 202],
# ['curry', 193],
# ['durant', 205],
# ['jordan', 199],
# ['david', 211]]
#players_iter = iter(players)
#while True:
# try:
# player = next(players_iter)
# if player[1] < 200:
# continue
# print(player)
# except StopIteration:
# break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment