Re: loop over list and process into groups

2010-03-05 Thread mk
st invented a cute ;-) two-liner using list comprehensions: # alist = list above tmp, dk = [], {} [(x.startswith('VLAN') and (dk.setdefault(x,[]) or tmp.append(x))) or (not x.startswith('VLAN') and dk[tmp[-1]].append(x))for x in alist if x != 'Interface'] No need to use a nuke like itertools to kill a fly. ;-) Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: loop over list and process into groups

2010-03-05 Thread mk
nn wrote: Oh my! You could have at least used some "if else" to make it a little bit easier on the eyes :-) That's my entry into """'Obfuscated' "Python" '"''code''"' '"contest"'""" and I'm proud of it. ;-) Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

isinstance(False, int)

2010-03-05 Thread mk
>>> isinstance(False, int) True >>> >>> isinstance(True, int) True Huh? >>> >>> issubclass(bool, int) True Huh?! Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: loop over list and process into groups

2010-03-05 Thread mk
lbolla wrote: It looks like Perl ;-) A positive proof that you can write perl code in Python. I, for instance, have had my brain warped by C and tend to write C-like code in Python. That's only half a joke, sadly. I'm trying to change my habits but it's hard. Regard

Re: isinstance(False, int)

2010-03-05 Thread mk
ery much. Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: isinstance(False, int)

2010-03-05 Thread mk
Rolando Espinoza La Fuente wrote: Doesn't have side effects not knowing that False/True are ints? It does, in fact I was wondering why my iterator didn't work until I figured issubclass(bool, int) is true. Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

imap vs map

2010-03-05 Thread mk
'], ['python'], ['list'], ['isnt', 'tins'], ['stop', 'post']] However, when I change the last line to: print map(list, map(itemgetter(1), gb)) It stops working: [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], ['post']] Why? I was under impression that the only difference between map and imap is that imap returns iterator allowing to produce a list, while map returns equivalent list? Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Text mining in Python

2010-03-10 Thread mk
as experience with them? Now, I do now about NLTK and Python bindings to UIMA. The thing is, I do not know if those are good for the above task. If somebody has experience with those or other and would be able to say if they're good for this, please post. Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: Anything like "Effective Java" for Python?

2010-03-11 Thread mk
nd it very readable. Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Loading C extension from memory

2010-05-13 Thread mk
s but there appear only methods of loading compiled Python (bytecode) modules. Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: Picking a license

2010-05-14 Thread mk
nd doesn't exclude MIT/Apache license for legal reasons? (this is obviously orthogonal to a technical question why static linking should be used sparringly if at all) Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

daemonizing after binding to port

2010-06-18 Thread mk
) os.chdir(globalpath) os.umask(0) Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: Updating python dictionary

2008-09-07 Thread MK Bernard
d accomplish this with something similar to the following: new_dict = {} for x in MAPPING_DICT.keys(): if x in my_dict.keys(): new_dict[MAPPING_DICT[x]] = my_dict[x] Although there is probably a better solution to the problem your having. Perhaps more details could help us lead in you the right direction? Cheers, MK -- http://mail.python.org/mailman/listinfo/python-list

Re: Updating python dictionary

2008-09-07 Thread MK Bernard
le input keys. > > If it doesn't include all possible input keys, answers will crash with > a KeyError. If there are any many:1 elements in the mapping (for > example, {'a': 'A', 'b': 'A'}), lossage happens. You may wish to code > in some checks for this. Thats exactly why I did an explicit check in my post, so as to make sure that such a collision could not occur. It would seem that something along what I posted would be safer, if less elegant, than the others. Cheers, MK -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3