0

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?

asked Nov 29, 2017 at 10:22
1
  • 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. Commented Nov 29, 2017 at 10:25

1 Answer 1

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.

answered Nov 29, 2017 at 10:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.