S
Steven Bethard
Here's what I'm doing:
.... if len(pair) != 2:
.... pair.append(None)
.... splits.append(pair)
.... [['1', None], ['1', '2'], ['3', None], ['-1', '4']]
Basically, I want to split each string into two items, substituting
None when no second item is specified in the string. (As you can see,
in my strings, the items are delimited by ':').
It seems like a simple enough operation that I should be able to write
a list comprehension for it, but I can't figure out how... Any
suggestions?
Steve
.... pair = s.split(':')lst = ['1', '1:2', '3', '-1:4']
splits = []
for s in lst:
.... if len(pair) != 2:
.... pair.append(None)
.... splits.append(pair)
.... [['1', None], ['1', '2'], ['3', None], ['-1', '4']]
Basically, I want to split each string into two items, substituting
None when no second item is specified in the string. (As you can see,
in my strings, the items are delimited by ':').
It seems like a simple enough operation that I should be able to write
a list comprehension for it, but I can't figure out how... Any
suggestions?
Steve