As a continuation of this question: split list items in python
Given a list:
l = ['element1\t0238.94', 'element2\t2.3904', 'element3\t0139847', '']
How to get everything after \t?
\t
I tried:
>>> [i.split('\t', 1)[1] for i in t] Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: list index out of range
Is it because I have ''in the end? How to exclude it?
''
In [175]: l = ['element1\t0238.94', 'element2\t2.3904', 'element3\t0139847', ''] In [176]: [i.partition('\t')[-1] for i in l] Out[176]: ['0238.94', '2.3904', '0139847', '']
Or, if you only want to consider elements with '\t'in them:
'\t'
In [177]: [i.partition('\t')[-1] for i in l if '\t' in i] Out[177]: ['0238.94', '2.3904', '0139847']
Your case is simpler because you can use that we throw everything away before the tab:
l = [x.split('\t')[-1] for x in l] ['0238.94', '2.3904', '0139847', '']
, [-1] [1], IndexError, ('', '\ t') ['']. '-1' " ", -1 1, , 0, 1.
['']
Source: https://habr.com/ru/post/1537031/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1537026/import-test-cases-to-testlink&usg=ALkJrhhkBVYOFMMu42EaMXBmOIqGQihvAQHow to use Tortoise SVN through local socks proxy and remote ssh server - svnSomething is wrong with JDialog - javaInfinite prototype inheritance in Javascript - javascriptJavaScript Inheritance (infinite loop when using superclass function) - javascriptКак вызвать ng-изменение в phantomjs - javascriptshm_open() не работает с EINVAL при создании разделяемой памяти в подкаталоге/dev/shm - linuxПассажирские Rails 4 App Startup = Uninitialized Constant ActiveModel:: Сериализатор - ruby-on-railsIE11 does not display image with object tag via web server, but excellent locally - htmlSQL - Overlapping Data Consolidation - sqlAll Articles