Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61192

Re: Eliminate "extra" variable

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <gary.herron@islandtraining.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'name?': 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'subject:extra': 0.09; 'worse': 0.09; 'def': 0.12; '1):': 0.16; 'igor': 0.16; 'keys.': 0.16; 'looping': 0.16; 'loops': 0.16; 'subject:variable': 0.16; 'there?': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'all,': 0.19; 'trying': 0.19; 'seems': 0.21; 'header:User-Agent:1': 0.23; 'received:emailsrvr.com': 0.24; 'rid': 0.24; 'looks': 0.24; 'source': 0.25; 'received:(smtp server)': 0.26; 'shown': 0.26; 'second': 0.26; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'waste': 0.30; 'code': 0.31; 'gary': 0.31; 'skip:d 20': 0.34; 'but': 0.35; 'there': 0.35; "didn't": 0.36; 'hi,': 0.36; 'list': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'you.': 0.62; 'complete': 0.62; "you've": 0.63; 'refer': 0.63; 'more': 0.64; 'fact,': 0.69; 'us,': 0.73
X-Virus-Scanned OK
Date Fri, 06 Dec 2013 15:28:20 -0800
From Gary Herron <gary.herron@islandtraining.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1
MIME-Version 1.0
To python-list@python.org
Subject Re: Eliminate "extra" variable
References <CA+FnnTzDjRzU65+VWnOwxfVR9FGMDgHLLmLEDOoGE0BMCptzEw@mail.gmail.com>
In-Reply-To <CA+FnnTzDjRzU65+VWnOwxfVR9FGMDgHLLmLEDOoGE0BMCptzEw@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3671.1386373001.18130.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386373001 news.xs4all.nl 2899 [2001:888:2000:d::a6]:56487
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61192

Show key headers only | View raw


On 12/06/2013 11:37 AM, Igor Korot wrote:
> 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}
>             dateStrs.append(dateStr)
>      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.

You want to build a list, but you don't want to give that list a name?  
Why not?  And how would you refer to that list in the second loop if it 
didn't have a name?

And concerning that second loop:  What are you trying to do there? It 
looks like a complete waste of time.  In fact, with what you've shown 
us, you can eliminate the variable dateStrs, and both loops and be no 
worse off.

Perhaps there is more to your code than you've shown to us ...

Gary Herron

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Eliminate "extra" variable Gary Herron <gary.herron@islandtraining.com> - 2013-12-06 15:28 -0800

csiph-web