Skip to content Skip to sidebar Skip to footer

List Verification. Upper And Lower Case

if current_name in mens_name or mens_name.upper(): print 'I know that name.' How would I verify the name, regardless of capitals?

Solution 1:

Lowercase or uppercase both strings:

if current_name.lower() in mens_name.lower()
    print'I know that name.'

No need for or here.

If mens_name is a list, you'll have to transform each element of the list; best to use any() to test for matches and bail out early:

current_name_lower = current_name.lower()
if any(current_name_lower == name.lower() for name in mens_name):
    print'I know that name.'

Solution 2:

Making all words in capital case so it will be:

mens_name_upper = [name.upper() for name in mens_name]

if current_name.upper() in mens_name_upper:
   print'I know that name.'

Solution 3:

Maybe this is not the best but will also works for you.

if isinstance(mens_name, list):
    names_upper = map(str.upper, mens_name)
else:
    names_upper = mens_name.upper()

if current_name.upper() in names_upper:
    #do the work here

Post a Comment for "List Verification. Upper And Lower Case"