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 support enumerate.
I have two semi related questions...
First, I am trying to output a list of strings to a csv file using the
csv module. The output file separates each letter of the string with a
comma and then puts each string on a separate line. So the code is:
import csv
output =
[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 of
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 if
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:
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,
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.
/F
--
http://mail.python.org/mailman/listinfo/python-list
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 are passing a
[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
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 an
10 matches
Mail list logo