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


Groups > comp.lang.python > #44159 > unrolled thread

Re: Running simultaneuos "FOR" loops

Started byinshu chauhan <insideshoes@gmail.com>
First post2013-04-23 12:43 +0530
Last post2013-04-23 08:59 +0000
Articles 3 — 3 participants

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.


Contents

  Re: Running simultaneuos "FOR" loops inshu chauhan <insideshoes@gmail.com> - 2013-04-23 12:43 +0530
    Re: Running simultaneuos "FOR" loops Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-04-23 09:38 +0200
    Re: Running simultaneuos "FOR" loops Duncan Booth <duncan.booth@invalid.invalid> - 2013-04-23 08:59 +0000

#44159 — Re: Running simultaneuos "FOR" loops

Frominshu chauhan <insideshoes@gmail.com>
Date2013-04-23 12:43 +0530
SubjectRe: Running simultaneuos "FOR" loops
Message-ID<mailman.959.1366701190.3114.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

This statement is giving me the following error

Statement:
for p, k, j in zip(sorted(segments.iterkeys(), class_count.iterkeys(),
pixel_count.iterkeys())):

Error:
Traceback (most recent call last):
  File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 170, in
<module>
    access_segments(segimage, data)
  File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 147, in
access_segments
    for p, k, j in zip(sorted(segments.iterkeys(), class_count.iterkeys(),
pixel_count.iterkeys())):
TypeError: 'dictionary-keyiterator' object is not callable





On Tue, Apr 23, 2013 at 12:33 PM, inshu chauhan <insideshoes@gmail.com>wrote:

> zip isn't doing the required
>
>
> On Tue, Apr 23, 2013 at 12:28 PM, inshu chauhan <insideshoes@gmail.com>wrote:
>
>> Yes Simultaneously means all three running at the same time, I looked up
>> zip just now, but will it not disturb my dictionaries ?
>> And yes the dictionaries have same number of keys.
>>
>> thanks
>>
>>
>> On Tue, Apr 23, 2013 at 12:16 PM, Chris Angelico <rosuav@gmail.com>wrote:
>>
>>> On Tue, Apr 23, 2013 at 4:40 PM, inshu chauhan <insideshoes@gmail.com>
>>> wrote:
>>> > i have to implement the below line in one of my code:
>>> >
>>> > for  p in sorted(segments.iterkeys()) and for k in
>>> > sorted(class_count.iterkeys()) and for j in
>>> sorted(pixel_count.iterkeys()):
>>> >
>>> > Its giving me a syntax error which is obvious, but how can I make all
>>> three
>>> > for loop run simultaneously or any other way to do this simultaneous
>>> work
>>> > ???
>>>
>>> Define simultaneously. Do the three dictionaries have the same number
>>> of keys? If so, look up zip() or itertools.izip; if not, you may have
>>> to more clearly define "simultaneous".
>>>
>>> ChrisA
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>
>>
>

[toc] | [next] | [standalone]


#44166

FromUlrich Eckhardt <ulrich.eckhardt@dominolaser.com>
Date2013-04-23 09:38 +0200
Message-ID<gdqh4a-u4p.ln1@satorlaser.homedns.org>
In reply to#44159
Am 23.04.2013 09:13, schrieb inshu chauhan:
> This statement is giving me the following error
>
> Statement:
> for p, k, j in zip(sorted(segments.iterkeys(), class_count.iterkeys(),
> pixel_count.iterkeys())):
>
> Error:
> Traceback (most recent call last):
>    File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 170, in
> <module>
>      access_segments(segimage, data)
>    File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 147, in
> access_segments
>      for p, k, j in zip(sorted(segments.iterkeys(), class_count.iterkeys(),
> pixel_count.iterkeys())):
> TypeError: 'dictionary-keyiterator' object is not callable

Which of the statements on that line causes the error? I guess asking 
yourself that question will lead you to the answer already! ;)

Any reason you quoted your own and several others' messages, am I 
missing some reference there?

Good luck!

Uli

[toc] | [prev] | [next] | [standalone]


#44168

FromDuncan Booth <duncan.booth@invalid.invalid>
Date2013-04-23 08:59 +0000
Message-ID<XnsA1AB65961CCB6duncanbooth@127.0.0.1>
In reply to#44159
inshu chauhan <insideshoes@gmail.com> wrote:

> This statement is giving me the following error
> 
> Statement:
> for p, k, j in zip(sorted(segments.iterkeys(), class_count.iterkeys(),
> pixel_count.iterkeys())):
> 
> Error:
> Traceback (most recent call last):
>   File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 170, in
><module>
>     access_segments(segimage, data)
>   File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 147, in
> access_segments
>     for p, k, j in zip(sorted(segments.iterkeys(),
>     class_count.iterkeys(), 
> pixel_count.iterkeys())):
> TypeError: 'dictionary-keyiterator' object is not callable
> 

The second argument to `sorted()` is a comparison or key function, if you 
want to sort all three key lists you need to sort them separately. Try:

for p, k, j in zip(sorted(segments),
                   sorted(class_count),
                   sorted(pixel_count)):

also you don't need to call the `iterkeys()` method as you need them all to 
sort and just treating the dict as a sequence will do the right thing.

-- 
Duncan Booth http://kupuguy.blogspot.com

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web