Multiline regex help
Steven Bethard
steven.bethard at gmail.com
Thu Mar 3 17:32:11 EST 2005
Kent Johnson wrote:
> for line in raw_data:
> if line.startswith('RelevantInfo1'):
> info1 = raw_data.next().strip()
> elif line.startswith('RelevantInfo2'):
> info2 = raw_data.next().strip()
> elif line.startswith('RelevantInfo3'):
> info3 = raw_data.next().strip()
> scores.setdefault(info1, {}).setdefault(info3, []).append(info2)
> info1 = info2 = info3 = None
Very pretty. =) I have to say, I hadn't ever used iterators this way
before, that is, calling their next method from within a for-loop. I
like it. =)
Thanks for opening my mind. ;)
STeVe
More information about the Python-list
mailing list