Eliminate "extra" variable

Igor Korot ikorot01 at gmail.com
Fri Dec 6 20:37:11 CET 2013

Hi, ALL,
I have following code:

def MyFunc(self, originalData):
     data = {}
     dateStrs = []
     for i in xrange(0, len(originalData)):
           dateStr, freq, source = originalData[i]
           data[str(dateStr)]  = {source: freq}
    for i in xrange(0, len(dateStrs) - 1):
          currDateStr = str(dateStrs[i])
          nextDateStrs = str(dateStrs[i + 1])

It seems very strange that I need the dateStrs list just for the
purpose of looping thru the dictionary keys.
Can I get rid of the "dateStrs" variable?

Thank you.

More information about the Python-list mailing list