python - Getting substring between nth and mth occurence of some sequence -
i want search string know contains several occurences of particular char sequence , retrieve what's between 2 of these occurences, numbered. or preferably, numbered end. want compact possible, goes inside list comprehension.
let's have following string:
s = "foofoo\tbergen, norway\taffluent\tdonkey"
i want retrieve substring of s situated between last occurence of "\t"
, penultimate occurence.
so in example: "affluent"
here comprehension using (without having pruned string):
data = [(entries[i], entries[i+1]) in range(0, len(entries), 3)]
it's string entries[i]
every entry data want prune.
rsplit
used split word right side
a="foofoo\tbergen, norway\taffluent\tdonkey" word= a.rsplit('\t',2) if len(word)>2: print word[-2] #output =affluent
Comments
Post a Comment