Spot the subtle error
2006-10-02 15:56#!/usr/bin/env python
# set up items, define is_type_x functions, etc
list_a = list_b = list_c = []
for item in items:
if is_type_a(item):
list_a.append(item)
elif is_type_b(item):
list_b.append(item)
elif is_type_c(item):
list_c.append(item)
else:
print 'wtf is this?',itemThe a = b = c = [] construct makes all three variables references to the same empty list. list.append() modifies the list in place. After this loop runs, all three lists will contain all of the items except those that aren't type a, b, or c.The most concise fix is to use list_a, list_b, list_c = [], [], [] as a replacement.
Don't ask how long I was beating my head against this one.
no subject
Date: 2006-10-02 20:16 (UTC)