Eliminate "extra" variable

Discussion in 'Python' started by Igor Korot, Dec 6, 2013.

  1. Igor Korot

    Igor Korot Guest

    Hi, ALL,
    I have following code:

    def MyFunc(self, originalData):
    data = {}
    dateStrs = []
    for i in xrange(0, len(originalData)):
    dateStr, freq, source = originalData
    data[str(dateStr)] = {source: freq}
    dateStrs.append(dateStr)
    for i in xrange(0, len(dateStrs) - 1):
    currDateStr = str(dateStrs)
    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.
     
    Igor Korot, Dec 6, 2013
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ixtahdoom
    Replies:
    1
    Views:
    575
    Gunnar Hjalmarsson
    Jul 9, 2004
  2. chandanlinster

    need for an extra variable.

    chandanlinster, Oct 31, 2006, in forum: C Programming
    Replies:
    13
    Views:
    494
    Jordan Abel
    Nov 1, 2006
  3. Replies:
    94
    Views:
    1,713
  4. mathieu
    Replies:
    3
    Views:
    892
    Bo Persson
    Sep 4, 2009
  5. Stefan Ram
    Replies:
    3
    Views:
    526
    Eric Sosman
    Apr 16, 2011
  6. Li Chen
    Replies:
    3
    Views:
    165
    Robert Klemme
    Sep 27, 2009
  7. Replies:
    7
    Views:
    221
    Joe Smith
    Jul 5, 2006
  8. Mark Lawrence

    Re: Eliminate "extra" variable

    Mark Lawrence, Dec 8, 2013, in forum: Python
    Replies:
    14
    Views:
    305
    Igor Korot
    Dec 16, 2013
Loading...