1

In this code, how can I check multiple strings in a single string in single statement?

line = '{        AutoLogin = 0;        Captive = 0;        Closed = 0;        Disabled = 0;        LastConnected = "2013-11-27 08:38:10 +0000";        Passpoint = 0;        PossiblyHiddenNetwork = 0;        SPRoaming = 0;        SSID = <534253>;        SSIDString = SBS;        SecurityType = "WPA/WPA2 Personal";        SystemMode = 1;        TemporarilyDisabled = 0;    })'

for token in line.split( ';' ):
    if 'RecentNetworks' in token:
        start = True
    if 'LastConnected' in token:
        start = True
1
  • Will be "line" a JSON, in this case maybe is easier parse the string as a json. Commented Nov 27, 2013 at 9:40

2 Answers 2

3

Try this:

for token in line.split(';'):
    start = any(s in token for s in ["RecentNetworks", "LastConnected"])
Sign up to request clarification or add additional context in comments.

Comments

0

You can use regular expressions for this:

if re.search(r'RecentNetworks|LastConnected', token):
    start = True

I'm not sure if this is faster than the any solution, but I assume it.

Comments

Your Answer

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.