Steven D'Aprano wrote:
> On Wed, 29 Nov 2006 17:00:30 +0100, Fredrik Lundh wrote:
>
>> Neil Cerutti wrote:
>>
BTW, iterating over range(len(a)) is an anti-pattern in Python.
>>>
>>> Unless you're modifying elements of a, surely?
>>
>> and needs to run on a Python version that doesn't suppo
On Wed, 29 Nov 2006 17:00:30 +0100, Fredrik Lundh wrote:
> Neil Cerutti wrote:
>
>>> BTW, iterating over range(len(a)) is an anti-pattern in Python.
>>
>> Unless you're modifying elements of a, surely?
>
> and needs to run on a Python version that doesn't support enumerate.
This isn't meant as
[EMAIL PROTECTED] wrote:
> I can try that. Is using range(len(a)) a bad solution in the sense
> that its likely to create an unexpected error? Or because there is a
> more efficient way to accomplish the same thing?
for-in uses an internal index counter to fetch items from the sequence, so
Roberto Bonvallet wrote:
> [EMAIL PROTECTED] wrote:
> > import csv
> > output = csv.writer(open('/Python25/working/output.csv', 'a'))
> > a = ["apple", "cranberry", "tart"]
> > for elem in range(len(a)):
> >output.writerow(a[elem])
>
> output.writerow expects a sequence as an argument. You ar
Neil Cerutti wrote:
>> BTW, iterating over range(len(a)) is an anti-pattern in Python.
>
> Unless you're modifying elements of a, surely?
and needs to run on a Python version that doesn't support enumerate.
--
http://mail.python.org/mailman/listinfo/python-list
On 2006-11-29, Roberto Bonvallet <[EMAIL PROTECTED]> wrote:
> Neil Cerutti wrote:
>> On 2006-11-29, Roberto Bonvallet <[EMAIL PROTECTED]> wrote:
>>> BTW, iterating over range(len(a)) is an anti-pattern in Python.
>>
>> Unless you're modifying elements of a, surely?
>
> enumerate is your friend :)
Neil Cerutti wrote:
> On 2006-11-29, Roberto Bonvallet <[EMAIL PROTECTED]> wrote:
>> BTW, iterating over range(len(a)) is an anti-pattern in Python.
>
> Unless you're modifying elements of a, surely?
enumerate is your friend :)
for n, item in enumerate(a):
if f(item):
a[n
On 2006-11-29, Roberto Bonvallet <[EMAIL PROTECTED]> wrote:
> BTW, iterating over range(len(a)) is an anti-pattern in Python.
Unless you're modifying elements of a, surely?
--
Neil Cerutti
You can't give him that cutback lane. He's so fast, and he sees it so well. He
can also run away from you i
[EMAIL PROTECTED] wrote:
> import csv
> output = csv.writer(open('/Python25/working/output.csv', 'a'))
> a = ["apple", "cranberry", "tart"]
> for elem in range(len(a)):
>output.writerow(a[elem])
output.writerow expects a sequence as an argument. You are passing a
string, which is a sequence o