Python hokus-pokus

items = db().select('items', project_id=project_id, in_history=0)

for item in items:
    child_ids = [int(id) for id in item.children.split(',')]

    if ids == child_ids:
        new_list = filter(lambda x: x not in ids, child_ids)
        db().update('items', id=item.id, children=','.join(new_list))
This little snippet of Python would probably be 50 lines in Java :)

Notice how you can compare lists (ids == child_ids) and it just works [unlike some other languages ... like JavaScript :)].

Code · Code improvement · Interesting · Python · Tips 21. Dec 2007
© Amir Salihefendic. Powered by Skeletonz.