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 happens

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 was that how the builtins

Re: Do this as a list comprehension?

2008-06-10 Thread Mensanator
this in a list comprehension where he doesn't have the option of iterating through both lists like he does with zip. When I mentioned that could be solved by enumerate, I said it simultaneously guaratees that the index numbers automatically end up the same length as the target list and avoids the hypothetical

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-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 two-item tuples?

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. --

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 habit to teach a

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 understood that

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? Works fine in

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 and it APPEARED that the

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, did you?

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: | zip(range(9,20),

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

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 the

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

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 comprehension

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 a

Re: Do this as a list comprehension?

2008-06-07 Thread Mensanator
* I never said a for..loop was preferable. What I said was the answer to Can I do this with a list comprehension? I never said you shouldn't use the builtins. 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

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

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, it

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 that

Re: Do this as a list comprehension?

2008-06-06 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, 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 own

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, 1, 1, 1,

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 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 two-item tuples? |

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 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 posted a

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 hardcoded his range bounds Hmm,

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, 2, 3, 3]

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 to write a list

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] | On Jun 5, 10:42?pm, John

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

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 of how