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
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)
True
>>>
>>> isinstance(True, int)
True
Huh?
>>>
>>> issubclass(bool, int)
True
Huh?!
Regards,
mk
--
http://mail.python.org/mailman/listinfo/python-list
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
ery much.
Regards,
mk
--
http://mail.python.org/mailman/listinfo/python-list
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
'], ['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
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
nd it very readable.
Regards,
mk
--
http://mail.python.org/mailman/listinfo/python-list
s but there appear only methods of loading compiled
Python (bytecode) modules.
Regards,
mk
--
http://mail.python.org/mailman/listinfo/python-list
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
)
os.chdir(globalpath)
os.umask(0)
Regards,
mk
--
http://mail.python.org/mailman/listinfo/python-list
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
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
201 - 214 of 214 matches
Mail list logo