1

If I have a few strings:

string1 = 'text here pri=1 more text urgent=True'
string2 = 'more text here pri=5 urgent=False'
string3 = 'another text pri=3 urgent=False'
string4 = 'more text pri=10 urgent=True'

how can I grab the value of "pri" and "urgent" from the string to a variable?

I came up with a few solutions like for pri just locating it using str.find and then jumping 4 variables ahead, etc....

but there must be a more efficient way to read it, how can I do so?

asked Mar 11, 2022 at 17:10
2

1 Answer 1

0

you can just use the .split() function to get all the different words. It would return a list. For string 1: ['text', 'here', 'pri=1', 'more', 'text', 'urgent=True'] so now you can loop through the list and search for '='.

answered Mar 11, 2022 at 17:17
Sign up to request clarification or add additional context in comments.

Comments

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.