I have a list that of items in a list that looks like this:
[u'1111 aaaa 20 0 250m 149m 113m S 0.0 2.2 532:09.83 bbbb', u' 5555 cccc 20 0 218m 121m 91m S 0.0 3.3 288:50.20 dddd']
The only thing from each item in the list I am concerned about is 2.2 and 3.3, but everything in each item is a variable and changes every time the process is run. The format will always be the same however.
Is there a way to regex each item in the list and check this value in each list?
-
Are you trying to get the value in place of 2.2 and 3.3 (the 10th value if delimiting by whitespace) or do you want to verify that the first string has 2.2 where it is and that the second string has 3.3 where it is? Please clarify your question.Galen– Galen2017年11月29日 10:25:49 +00:00Commented Nov 29, 2017 at 10:25
1 Answer 1
If you want to just get the 2.2
and 3.3
values, you can go without regexps:
data = [u'1111 aaaa 20 0 250m 149m 113m S 0.0 2.2 532:09.83 bbbb', u' 5555 cccc 20 0 218m 121m 91m S 0.0 3.3 288:50.20 dddd']
print([item.split()[9] for item in data]) # yields [u'2.2', u'3.3']
By default split
splits by whitespace. And your 2.2
and 3.3
numbers happen to be 10th in each of the blobs. Python uses 0-indexing of lists, so 10th in human terms becomes 9
.