Re: Do this as a list comprehension?

2008-06-10 Thread Mensanator
On Jun 10, 6:09 pm, Lie <[EMAIL PROTECTED]> wrote: > On Jun 8, 11:11 pm, Mensanator <[EMAIL PROTECTED]> wrote: > > > > > > > On Jun 8, 4:04 am, Lie <[EMAIL PROTECTED]> wrote: > > > > On Jun 8, 8:56 am, Mensanator <[EMAIL PROTECTED]> wrote: > > > > > On Jun 7, 8:22�pm, John Salerno <[EMAIL PROTECTED

Re: Do this as a list comprehension?

2008-06-10 Thread Lie
On Jun 8, 11:11 pm, Mensanator <[EMAIL PROTECTED]> wrote: > On Jun 8, 4:04 am, Lie <[EMAIL PROTECTED]> wrote: > > > > > On Jun 8, 8:56 am, Mensanator <[EMAIL PROTECTED]> wrote: > > > > On Jun 7, 8:22�pm, John Salerno <[EMAIL PROTECTED]> wrote: > > > > > Mensanator wrote: > > > > > What I DID say wa

Re: Do this as a list comprehension?

2008-06-10 Thread John Salerno
"Mensanator" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Jun 8, 9:40 pm, John Salerno <[EMAIL PROTECTED]> wrote: > Mensanator wrote: > Heh heh, don't worry. Every time I see a range function, I immediately > think "creates a list". Not sure how I got into that habit, but it > h

Re: Do this as a list comprehension?

2008-06-09 Thread Jason Scheirer
On Jun 9, 7:06 am, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: > Mensanator wrote: > > On Jun 6, 1:40 pm, The Pythonista <[EMAIL PROTECTED]> wrote: > >> On Thu, 05 Jun 2008 23:42:07 -0400, John Salerno wrote: > >>> Is it possible to write a list comprehension for this so as to produce a > >>> list of

Re: Do this as a list comprehension?

2008-06-09 Thread Ricardo Aráoz
Mensanator wrote: On Jun 6, 1:40 pm, The Pythonista <[EMAIL PROTECTED]> wrote: On Thu, 05 Jun 2008 23:42:07 -0400, John Salerno wrote: Is it possible to write a list comprehension for this so as to produce a list of two-item tuples? base_scores = range(8, 19) score_costs = [0, 1, 1, 1, 1, 1, 1,

Re: Do this as a list comprehension?

2008-06-08 Thread Mensanator
On Jun 8, 9:40 pm, John Salerno <[EMAIL PROTECTED]> wrote: > Mensanator wrote: > > On Jun 8, 3:19�am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > >> "Mensanator" <[EMAIL PROTECTED]> wrote in message > > >>news:[EMAIL PROTECTED] > >> | On Jun 7, 6:43?pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > >>

Re: Do this as a list comprehension?

2008-06-08 Thread John Salerno
Mensanator wrote: On Jun 8, 3:19�am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: "Mensanator" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On Jun 7, 6:43?pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: | > zip(range(9,20), iterable) | | Oh, dear. You didn't actually try this,

Re: Do this as a list comprehension?

2008-06-08 Thread Mensanator
On Jun 8, 4:04 am, Lie <[EMAIL PROTECTED]> wrote: > On Jun 8, 8:56 am, Mensanator <[EMAIL PROTECTED]> wrote: > > > > > > > On Jun 7, 8:22�pm, John Salerno <[EMAIL PROTECTED]> wrote: > > > > Mensanator wrote: > > > > What I DID say was that how the builtins actually > > > > work should be understood

Re: Do this as a list comprehension?

2008-06-08 Thread Mensanator
On Jun 8, 3:19�am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Mensanator" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > | On Jun 7, 6:43?pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > | > zip(range(9,20), iterable) > | > | Oh, dear. You didn't actually try this, did you

Re: Do this as a list comprehension?

2008-06-08 Thread Lie
On Jun 8, 8:56 am, Mensanator <[EMAIL PROTECTED]> wrote: > On Jun 7, 8:22�pm, John Salerno <[EMAIL PROTECTED]> wrote: > > > Mensanator wrote: > > > What I DID say was that how the builtins actually > > > work should be understood and it APPEARED that the > > > OP didn't understand that. Maybe he un

Re: Do this as a list comprehension?

2008-06-08 Thread Lie
On Jun 8, 12:24 am, Mensanator <[EMAIL PROTECTED]> wrote: > On Jun 7, 5:21�am, Paul Miller <[EMAIL PROTECTED]> wrote: > > > On Fri, 06 Jun 2008 18:01:45 -0700, Mensanator wrote: > > > What happens if your iterables aren't the same length? > > > I chose not to consider that case, > > That's a bad ha

Re: Do this as a list comprehension?

2008-06-08 Thread Terry Reedy
"Mensanator" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On Jun 7, 6:43?pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: | > zip(range(9,20), iterable) | | Oh, dear. You didn't actually try this, did you? Works fine in Py3, which is what I use now. -- http://mail.python.

Re: Do this as a list comprehension?

2008-06-07 Thread Mensanator
On Jun 7, 8:22�pm, John Salerno <[EMAIL PROTECTED]> wrote: > Mensanator wrote: > > What I DID say was that how the builtins actually > > work should be understood and it APPEARED that the > > OP didn't understand that. Maybe he understood that > > all along but his example betrayed no evidence of >

Re: Do this as a list comprehension?

2008-06-07 Thread Paul Hankin
On Jun 7, 7:21 pm, Paul Miller <[EMAIL PROTECTED]> wrote: > On Fri, 06 Jun 2008 18:01:45 -0700, Mensanator wrote: > > What happens if your iterables aren't the same length? > > I chose not to consider that case, since they were the same length in the > original post.  Based on the variable names, i

Re: Do this as a list comprehension?

2008-06-07 Thread John Salerno
Mensanator wrote: What I DID say was that how the builtins actually work should be understood and it APPEARED that the OP didn't understand that. Maybe he understood that all along but his example betrayed no evidence of that understanding. Well, the truth is that I know zip truncates to the s

Re: Do this as a list comprehension?

2008-06-07 Thread Mensanator
On Jun 7, 6:43�pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "John Salerno" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED]| Mensanator wrote: > > | > | > Surely enumerate() wasn't added to Python with no intention of > | > ever being used. > | > | I see your reasons for preferring

Re: Do this as a list comprehension?

2008-06-07 Thread Terry Reedy
"John Salerno" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Mensanator wrote: | | > Surely enumerate() wasn't added to Python with no intention of | > ever being used. | | I see your reasons for preferring enumerate over zip, but I'm wondering | if using enumerate this way isn't

Re: Do this as a list comprehension?

2008-06-07 Thread Mensanator
On Jun 7, 1:16�pm, John Salerno <[EMAIL PROTECTED]> wrote: > Mensanator wrote: > > Surely enumerate() wasn't added to Python with no intention of > > ever being used. > > I see your reasons for preferring enumerate over zip, It's not that I prefer it, it's that you specifically asked a list compre

Re: Do this as a list comprehension?

2008-06-07 Thread John Salerno
Mensanator wrote: Surely enumerate() wasn't added to Python with no intention of ever being used. I see your reasons for preferring enumerate over zip, but I'm wondering if using enumerate this way isn't a little hackish or artificial. Isn't the point of enumerate to get the index of a speci

Re: Do this as a list comprehension?

2008-06-07 Thread Mensanator
On Jun 7, 5:21�am, Paul Miller <[EMAIL PROTECTED]> wrote: > On Fri, 06 Jun 2008 18:01:45 -0700, Mensanator wrote: > > What happens if your iterables aren't the same length? > > I chose not to consider that case, That's a bad habit to teach a newbie, isn't it? > since they were the same length in

Re: Do this as a list comprehension?

2008-06-07 Thread Paul Miller
On Fri, 06 Jun 2008 18:01:45 -0700, Mensanator wrote: > What happens if your iterables aren't the same length? I chose not to consider that case, since they were the same length in the original post. Based on the variable names, it seemed reasonable that there would always be a 1-to-1 corresp

Re: Do this as a list comprehension?

2008-06-06 Thread Mensanator
On Jun 6, 10:33 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Mensanator" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > On Jun 6, 1:44 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > > > > > > > "Mensanator" <[EMAIL PROTECTED]> wrote in message > > >news:[EMAIL PROTECTED] > > |

Re: Do this as a list comprehension?

2008-06-06 Thread Terry Reedy
"Mensanator" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Jun 6, 1:44 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Mensanator" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > | On Jun 5, 10:42?pm, John Salerno <[EMAIL PROTECTED]> wrote: > | > Is it possible

Re: Do this as a list comprehension?

2008-06-06 Thread Mensanator
On Jun 6, 1:40 pm, The Pythonista <[EMAIL PROTECTED]> wrote: > On Thu, 05 Jun 2008 23:42:07 -0400, John Salerno wrote: > > Is it possible to write a list comprehension for this so as to produce a > > list of two-item tuples? > > > base_scores = range(8, 19) > > score_costs = [0, 1, 1, 1, 1, 1, 1, 2

Re: Do this as a list comprehension?

2008-06-06 Thread Mensanator
On Jun 6, 3:19 pm, "John Salerno" <[EMAIL PROTECTED]> wrote: > "Mensanator" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > On Jun 6, 1:44 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > > > "Mensanator" <[EMAIL PROTECTED]> wrote in message > > And since the OP foolishly > hardcode

Re: Do this as a list comprehension?

2008-06-06 Thread John Salerno
"Mensanator" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Jun 6, 1:44 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Mensanator" <[EMAIL PROTECTED]> wrote in message And since the OP foolishly hardcoded his range bounds Hmm, I just love the arrogance of some people. I actually

Re: Do this as a list comprehension?

2008-06-06 Thread The Pythonista
On Thu, 05 Jun 2008 23:42:07 -0400, John Salerno wrote: > Is it possible to write a list comprehension for this so as to produce a > list of two-item tuples? > > base_scores = range(8, 19) > score_costs = [0, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3] print zip(base_scores, > score_costs) > score_costs = [(

Re: Do this as a list comprehension?

2008-06-06 Thread Mensanator
On Jun 6, 1:44 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Mensanator" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > | On Jun 5, 10:42?pm, John Salerno <[EMAIL PROTECTED]> wrote: > | > Is it possible to write a list comprehension for this so as to produce > a > | > list of t

Re: Do this as a list comprehension?

2008-06-06 Thread John Salerno
"Terry Reedy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > "Mensanator" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > Which is exactly the purpose of zip, or its specialization enumerate! Thanks guys! Looks like the simplest is always the best yet again! :)

Re: Do this as a list comprehension?

2008-06-06 Thread Marc 'BlackJack' Rintsch
On Thu, 05 Jun 2008 23:56:40 -0700, dwahli wrote: > On Jun 6, 8:44 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: >> >> Of course, enumerate(iterable) is just a facade over zip(itertools.count(), >> iterable) > > So you could write: > gen = (x for x in itertools.izip(itertools.count(8), [0, 1, 1, 1

Re: Do this as a list comprehension?

2008-06-06 Thread dwahli
On Jun 6, 8:44 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > > Of course, enumerate(iterable) is just a facade over zip(itertools.count(), > iterable) So you could write: gen = (x for x in itertools.izip(itertools.count(8), [0, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3])) print list(gen) Using zip like you o

Re: Do this as a list comprehension?

2008-06-05 Thread Terry Reedy
"Mensanator" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On Jun 5, 10:42?pm, John Salerno <[EMAIL PROTECTED]> wrote: | > Is it possible to write a list comprehension for this so as to produce a | > list of two-item tuples? | > | > base_scores = range(8, 19) | > score_costs = [0

Re: Do this as a list comprehension?

2008-06-05 Thread Mensanator
On Jun 5, 10:42�pm, John Salerno <[EMAIL PROTECTED]> wrote: > Is it possible to write a list comprehension for this so as to produce a > list of two-item tuples? > > base_scores = range(8, 19) > score_costs = [0, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3] > print zip(base_scores, score_costs) > > I can't think

Do this as a list comprehension?

2008-06-05 Thread John Salerno
Is it possible to write a list comprehension for this so as to produce a list of two-item tuples? base_scores = range(8, 19) score_costs = [0, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3] print zip(base_scores, score_costs) I can't think of how the structure of the list comprehension would work in this case,