dict.items() vs dict.iteritems and similar questions

Drew olsonas at gmail.com
Wed Mar 14 11:30:27 EDT 2007


When is it appropriate to use dict.items() vs dict.iteritems. Both
seem to work for something like:

for key,val in mydict.items():
  print key,val

for key,val in mydict.iteritems():
  print key,val

Also, when is it appropriate to use range() vs xrange(). From my
understanding, xrange() essentially gives you an iterator across a
range, so it should be used when iterating. Should you only use
range() when want to physically store the range as a list?

Thanks,
Drew




More information about the Python-list mailing list