string splitting

stefaan stefaan.himpe at gmail.com
Wed Oct 18 00:06:32 CEST 2006


> Anyone have any ideas?

l = "wisconsin_state.txt"
l.split(".")[0].split("_")[-1]

Explanation:
-------------------
the split(".")[0] part takes everything before the "."

the split("_")[-1] part selects in the last element in the list of
substrings which are separated by "_"




More information about the Python-list mailing list