Advertisement
here2share

# enumerateVSrange.py

Jun 21st, 2015
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. # enumerateVSrange.py
  2.  
  3. subj = '123 xyz abc Python!'
  4. subj=subj.split()
  5.  
  6. # Non-Pythonic Way...
  7.  
  8. for i in range(len(subj)) :
  9.     print subj[i]
  10. print
  11.  
  12. # Instead, Do...
  13.  
  14. for elem in subj :
  15.     print elem
  16. print
  17. # ... since it should automate the iteration operations for you.
  18. # Or... if both the index and element are needed.
  19.  
  20. for i, elem in enumerate(subj):
  21.      print i, elem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement