I have file that contains values separated by tab (\"\\t\"). I am trying to create a list and store all values of file in the list. But I get some problem. Here is my code.<
You can use regex here:
regex
>>> import re >>> strs = "foo\tbar\t\tspam" >>> re.split(r'\t+', strs) ['foo', 'bar', 'spam']
update:
You can use str.rstrip to get rid of trailing '\t' and then apply regex.
str.rstrip
'\t'
>>> yas = "yas\t\tbs\tcda\t\t" >>> re.split(r'\t+', yas.rstrip('\t')) ['yas', 'bs', 'cda']