Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
list comprehension problems
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rodney Snell  
View profile  
 More options Jun 26, 12:13 pm
From: Rodney Snell <snells...@gmail.com>
Date: Fri, 26 Jun 2009 09:13:11 -0700 (PDT)
Local: Fri, Jun 26 2009 12:13 pm
Subject: list comprehension problems
I can't figure out why the following script (run using booi) does not
generate output like I expect:
---------------------------------------------
l = ["1","2","3","4","5"]
s as string

mylist = [s for s in l if s == "2"]
print mylist      #I would expect mylist = ["2"] here, but it is []

mylist = [s for s in l if s.Contains("2")]
print mylist      #Generates an object ref=null exception
--------------------------------------------

In fact, almost every comprehension I try fails.  This snippet
produces [0,0,0,0,0]:

l = [1,2,3,4,5]
i as int
mylist = [i for i in l if i < 2]
print mylist

What am I missing here?  Thanks in advance.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cedric Vivier  
View profile  
 More options Jun 26, 12:26 pm
From: Cedric Vivier <cedr...@neonux.com>
Date: Sat, 27 Jun 2009 00:26:11 +0800
Local: Fri, Jun 26 2009 12:26 pm
Subject: Re: list comprehension problems

On Sat, Jun 27, 2009 at 12:13 AM, Rodney Snell <snells...@gmail.com> wrote:
> In fact, almost every comprehension I try fails.  This snippet
> produces [0,0,0,0,0]:

> l = [1,2,3,4,5]
> i as int
> mylist = [i for i in l if i < 2]
> print mylist

> What am I missing here?  Thanks in advance.

Interesting bug.
It works in the interpreter but not with the compiler.
With the compiler you declare 'i' this way for it to work:
mylist = [i for i as int in l if i < 2]

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rodney Snell  
View profile  
 More options Jun 26, 5:24 pm
From: Rodney Snell <snells...@gmail.com>
Date: Fri, 26 Jun 2009 14:24:36 -0700 (PDT)
Local: Fri, Jun 26 2009 5:24 pm
Subject: Re: list comprehension problems
Thanks Cedric.  Putting the 'as' cast inline works for me too (both
booi and booc).
Not sure what the difference is.  The thing I don't like about it is
that it clutters the comprehension syntax making it less readable.
But that will do for now - thanks again!

On Jun 26, 9:26 am, Cedric Vivier <cedr...@neonux.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Justin Chase  
View profile  
 More options Jun 27, 11:34 am
From: Justin Chase <justin.m.ch...@gmail.com>
Date: Sat, 27 Jun 2009 10:34:20 -0500
Local: Sat, Jun 27 2009 11:34 am
Subject: Re: list comprehension problems

If the list was generic could it infer the type?

--
Justin Chase
http://www.justnbusiness.com

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cedric Vivier  
View profile  
 More options Jun 27, 3:15 pm
From: Cedric Vivier <cedr...@neonux.com>
Date: Sun, 28 Jun 2009 03:15:57 +0800
Local: Sat, Jun 27 2009 3:15 pm
Subject: Re: list comprehension problems

On Sat, Jun 27, 2009 at 11:34 PM, Justin Chase <justin.m.ch...@gmail.com>wrote:

> If the list was generic could it infer the type?

Indeed.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google