Re: please help shrink this each_with_index() implementation

2010-01-08 Thread Roel Schroeven
Phlip schreef: Nobody wrote: Writing robust software from the outset puts you at a competitive disadvantage to those who understand how the system works. And I, not my language, should pick and chose how to be rigorous. The language should not make the decision for me. You can always

Re: please help shrink this each_with_index() implementation

2010-01-06 Thread Nobody
On Tue, 05 Jan 2010 12:20:58 -0800, Marco Nawijn wrote: You could use the build-in function enumerate inside a list comprehension. seq = range(5) [ (i,s) for i,s in enumerate(seq) ] [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)] Just use list(), i.e. list(enumerate(seq)). --

Re: please help shrink this each_with_index() implementation

2010-01-06 Thread Carl Banks
On Jan 5, 2:40 pm, Phlip phlip2...@gmail.com wrote: On Jan 5, 1:10 pm, Antoine Pitrou solip...@pitrou.net wrote: http://docs.python.org/library/functions.html Don't forget that the Python documentation is rich and structured. And good luck. Does it say how to convert a string containing

Re: please help shrink this each_with_index() implementation

2010-01-06 Thread Nobody
On Tue, 05 Jan 2010 19:46:01 -0800, alex23 wrote: They will tell me how to use except: (which is a good example why a program should not use exceptions for its normal control flow if at all possible). Really? Magic functions that coerce and eat errors are a better coding technique than

Re: please help shrink this each_with_index() implementation

2010-01-06 Thread Phlip
Nobody wrote: On Tue, 05 Jan 2010 19:46:01 -0800, alex23 wrote: They will tell me how to use except: (which is a good example why a program should not use exceptions for its normal control flow if at all possible). Really? Magic functions that coerce and eat errors are a better coding

Re: please help shrink this each_with_index() implementation

2010-01-06 Thread Steven D'Aprano
On Wed, 06 Jan 2010 12:12:08 -0800, Phlip wrote: And I, not my language, should pick and chose how to be rigorous. The language should not make the decision for me. All languages make that decision for you by making some thing possible and other things not. The language designer, not the

Re: please help shrink this each_with_index() implementation

2010-01-06 Thread Antoine Pitrou
Le Wed, 06 Jan 2010 12:12:08 -0800, Phlip a écrit : And I, not my language, should pick and chose how to be rigorous. The language should not make the decision for me. And that's why there is the try: ... except: ... construct. Your rant is getting tiring. --

Re: please help shrink this each_with_index() implementation

2010-01-06 Thread alex23
Phlip phlip2...@gmail.com wrote: And I, not my language, should pick and chose how to be rigorous. The language should not make the decision for me. Since you seem unwilling to put the minimal effort into producing the support code you'd need to work with Python the way you want, perhaps Perl

Re: please help shrink this each_with_index() implementation

2010-01-06 Thread Carl Banks
On Jan 6, 12:12 pm, Phlip phlip2...@gmail.com wrote: Nobody wrote: Writing robust software from the outset puts you at a competitive disadvantage to those who understand how the system works. And I, not my language, should pick and chose how to be rigorous. The language should not make the

please help shrink this each_with_index() implementation

2010-01-05 Thread Phlip
Hypo Nt: def each_with_index(seq): index = 0 result = [] for item in seq: result.append([item, index]) index += 1 return result My Pythonic sequencing skills are obviously feeble. Can anything think of a way to write that in fewer lines? -- Phlip

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread akean
On Jan 6, 8:58 am, Phlip phlip2...@gmail.com wrote: Hypo Nt: def each_with_index(seq):     index = 0     result = []     for item in seq:       result.append([item, index])       index += 1     return result My Pythonic sequencing skills are obviously feeble. Can anything think of a

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread Carsten Haese
Phlip wrote: Hypo Nt: def each_with_index(seq): index = 0 result = [] for item in seq: result.append([item, index]) index += 1 return result My Pythonic sequencing skills are obviously feeble. Can anything think of a way to write that in fewer lines?

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread Marco Nawijn
On Jan 5, 8:58 pm, Phlip phlip2...@gmail.com wrote: Hypo Nt: def each_with_index(seq):     index = 0     result = []     for item in seq:       result.append([item, index])       index += 1     return result My Pythonic sequencing skills are obviously feeble. Can anything think of a

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread Phlip
My Pythonic sequencing skills are obviously feeble. Can anything think of a way to write that in fewer lines? Thanks, all! Couldn't you just use the built-in enumerate() to replace the whole thing? Because that would involve, like, reading an entire Python book just to locate that method?

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread Antoine Pitrou
Couldn't you just use the built-in enumerate() to replace the whole thing? Because that would involve, like, reading an entire Python book just to locate that method? Actually, no. It just involves reading one of the most important pages in the documentation, the page which describes the

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread Phlip
On Jan 5, 1:10 pm, Antoine Pitrou solip...@pitrou.net wrote: http://docs.python.org/library/functions.html Don't forget that the Python documentation is rich and structured. And good luck. Does it say how to convert a string containing either an integer representation, or something

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread Steven D'Aprano
On Tue, 05 Jan 2010 14:40:49 -0800, Phlip wrote: On Jan 5, 1:10 pm, Antoine Pitrou solip...@pitrou.net wrote: http://docs.python.org/library/functions.html Don't forget that the Python documentation is rich and structured. And good luck. Does it say how to convert a string containing

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread Phlip
Does it say how to convert a string containing either an integer representation, or something alphabetic, into an integer, or a zero, in like 1 method call? (No except: ?) If you mean something like this: int('153') 153 The point: int('') or int('something') both throw an error. In

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread Mackrackit
On Jan 5, 2010, at 4:30 PM, Phlip phlip2...@gmail.com wrote: The point: int('') or int('something') both throw an error. In general, this is hand-holding, but in specific I don't think the rich and structured documentation will cover how to beat a 0 out of it in less than 3 lines. So I will

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread Antoine Pitrou
The point: int('') or int('something') both throw an error. In general, this is hand-holding, but in specific I don't think the rich and structured documentation will cover how to beat a 0 out of it in less than 3 lines. Because it's a bad idea to do so and Python doesn't encourage such

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread MRAB
Antoine Pitrou wrote: The point: int('') or int('something') both throw an error. In general, this is hand-holding, but in specific I don't think the rich and structured documentation will cover how to beat a 0 out of it in less than 3 lines. Because it's a bad idea to do so and Python doesn't

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread alex23
Phlip phlip2...@gmail.com wrote: They will tell me how to use except: (which is a good example why a program should not use exceptions for its normal control flow if at all possible). Really? Magic functions that coerce and eat errors are a better coding technique than exceptions and explicit

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread Steven D'Aprano
On Tue, 05 Jan 2010 15:30:09 -0800, Phlip wrote: Does it say how to convert a string containing either an integer representation, or something alphabetic, into an integer, or a zero, in like 1 method call? (No except: ?) If you mean something like this: int('153') 153 The point:

Re: please help shrink this each_with_index() implementation

2010-01-05 Thread alex23
Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: Stick around and you might learn something, but if you bite every time somebody tries to teach you, you'll soon run out of people willing to help you. The ongoing crowdsourced development by this group of Victor Subervi's project