string splitting

stefaan stefaan.himpe at gmail.com
Tue Oct 17 18:06:32 EDT 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