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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -