2
Data={
    0:{
       'country1': "Ryan lives in America",
       'country_one': "5",
       'med_dict':{
          0: {
              'endDate': "732",
              'endTime': "89",
             }
       },
     },
    1: {
        'country1': "Sam lives in america",
        'country_three': "90",
        'med_dict': {
          0: {
              'endDate': "245",
              'endTime': "222",
              }
        },

    }
}

res = [v1['country1'] for k1, v1 in Data.items()]
print(res)

I have got the output as ['Ryan lives in America', 'Sam lives in america']. I want to print True if word 'America/america' is present in both the string or else print False. Need to check for the case sensitivity as lower or upper. How to do it?

2 Answers 2

1

If maybe you want to check multiple words, you can create list of words and use any.

chk = ['America', 'americ']

res = [any(c in v1['country1'] for c in chk) for k1,v1 in Data.items()]
print(res)

# If you want to check and print
if all(res):
    print('True')
else:
    print('False')

[True, True]
Sign up to request clarification or add additional context in comments.

Comments

1

Use lower to do the case insensitive comparison, and then all on boolean values:

res = all("america" in v1['country1'].lower() for k1, v1 in Data.items())
print(res)

Output

True

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.