Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61192
| Date | 2013-12-06 15:28 -0800 |
|---|---|
| From | Gary Herron <gary.herron@islandtraining.com> |
| Subject | Re: Eliminate "extra" variable |
| References | <CA+FnnTzDjRzU65+VWnOwxfVR9FGMDgHLLmLEDOoGE0BMCptzEw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3671.1386373001.18130.python-list@python.org> (permalink) |
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
Re: Eliminate "extra" variable Gary Herron <gary.herron@islandtraining.com> - 2013-12-06 15:28 -0800
csiph-web