ckd: (cpu)
[personal profile] ckd
#!/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?',item
The 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.

Date: 2006-10-04 00:21 (UTC)
From: [identity profile] dd-b.livejournal.com
I'm glad somebody covered this before I got to it :-).

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.

Profile

ckd: small blue foam shark (Default)
blue shark of friendliness

January 2026

S M T W T F S
    123
4 5678910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated 2026-01-23 19:01
Powered by Dreamwidth Studios