Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61192 > unrolled thread
| Started by | Gary Herron <gary.herron@islandtraining.com> |
|---|---|
| First post | 2013-12-06 15:28 -0800 |
| Last post | 2013-12-06 15:28 -0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Eliminate "extra" variable Gary Herron <gary.herron@islandtraining.com> - 2013-12-06 15:28 -0800
| From | Gary Herron <gary.herron@islandtraining.com> |
|---|---|
| Date | 2013-12-06 15:28 -0800 |
| Subject | Re: Eliminate "extra" variable |
| Message-ID | <mailman.3671.1386373001.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web