[Tutor] Program gets stuck after a creating a list from dictinary items!

Prasad, Ramit ramit.prasad at jpmorgan.com
Fri Jul 6 18:54:55 CEST 2012


Please do not top post.

> 
> BTW I changed it to:
> D=[prog[key1] for key1 in list(sCommonFeatures)]
> 
> because sCommonFeatures is actually a set, but it still has the smae problem
> On Fri, Jul 6, 2012 at 12:27 PM, Ali Torkamani <torkamani at gmail.com> wrote:
> Thanks, I checked,  FD is not empty,
> Thanks for reminding about the flush and close, but I think some thing is
> wrong with:
> 
> D=[prog[key1] for key1 in sCommonFeatures]
> In the debug mode it works fine from the command line, but in the for loop it
> gets stuck.

I believe that the usage of 'in <blah>' converts it into a set (or 
set-like) object so probably that is the same as set(list(set())).

Again what do you mean by "stuck"? Does it error or do you just wait? 
Can you provide a small sample script (including sample sCommonFeatures and FD) ?
What version of Python / operating system?

> I could resolve it by defining a small function:
> 
> def getValue(mydict,keys):
>     A=[];
>     for i in keys:
>         A=A+[mydict[i]]
>     return A
> 
> and then calling it: D=getValue(prog,sCommonFeatures);
> (instead of D=[prog[key1] for key1 in list(sCommonFeatures)];)
> 
> but I'm still surprised why the latter one didn't work!

It would be more efficient to do the following

def getValue(mydict, keys):
    A=[]
    for i in keys:
        A.append( mydict[i] )
    return A


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  


More information about the Tutor mailing list