eval ?
Lonnie Princehouse
fnord at u.washington.edu
Fri Feb 20 13:18:09 EST 2004
Hi Angelo,
Welcome to Python =)
Why not make a list of lists? I.e.
lists = [ [] for i in range(3) ]
for my_list in lists:
for i in range(6):
if some_condition(i):
my_list.append(1)
It's generally best to avoid eval if you don't need it. And some tips-
1. Don't use "list" as a variable name. It's a builtin type!
2. Iterate over objects in lists directly, not with an index, unless you
actually need the index for something. Example,
for obj in obj_list:
print obj
instead of
for i in range(len(obj_list)):
print obj_list[i]
3. Don't use the same variable name "index" for both for loops.
4. String formatters!
"list%s = my_list" % index
is more readable than
"list" + str(index) + " = my_list"
More information about the Python-list
mailing list