Spot the subtle error
#!/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
no subject
no subject
(Beating my head against the keyboard brings out my inner philosopher.)
no subject
no subject
Of course, one might claim that that is not a *subtle* error.
My particular forehead-basher this afternoon involves tcl and expect. I think I'm developing a good-sized lump.
no subject
no subject
$z = $y = $x = \( ); (or, alternately, $z = $y = $x = []; - but that's specifically defined as returning a reference to an array.)
IMNSHO, if you want to have a reference/pointer/whateveryouwannacallit, you should explicitly ask for one.
no subject
(thank goodness for folks like you)
:-)
no subject