Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # enumerateVSrange.py
- subj = '123 xyz abc Python!'
- subj=subj.split()
- # Non-Pythonic Way...
- for i in range(len(subj)) :
- print subj[i]
- print
- # Instead, Do...
- for elem in subj :
- print elem
- print
- # ... since it should automate the iteration operations for you.
- # Or... if both the index and element are needed.
- for i, elem in enumerate(subj):
- print i, elem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement