-1
if current_name in mens_name or mens_name.upper():
    print 'I know that name.'

How would I verify the name, regardless of capitals?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
user3264459
  • 15
  • 1
  • 4
  • Please stop writing random things and expecting them to work. – Oleh Prypin Feb 03 '14 at 22:43
  • @jonrsharpe I'm amused by picking out a specific duplicate here, because this has got to be **the** single most asked question (in many different forms) - the most common problem beginners have with logic. – Karl Knechtel Feb 03 '14 at 22:44
  • 1
    @KarlKnechtel I've actually (very briefly) though about writing a bot scanning for questions containing `if ... or ...:` and posting some generic answer to them! :-) Still, I do not consider _this_ question a duplicate, since the actual problem is that `mens_name` is a list. – tobias_k Feb 03 '14 at 22:47

3 Answers3

2

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.'
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
1

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.'
  • does not work. How can you say you put in name.upper(). Don't you have to declare name? – user3264459 Feb 03 '14 at 23:16
  • nevermind. sorry it works, but I am still confused on why you can just put name.upper()? – user3264459 Feb 03 '14 at 23:17
  • name already declared in the for loop. the code is lopping over names in mens_name list and convert it to upper case – Mohamed Abd El Raouf Feb 03 '14 at 23:18
  • so that basically allows you to call upper on a list? – user3264459 Feb 03 '14 at 23:24
  • upper is called using string name. the for loop meaning is that for each name in names do something in this name, so the for loop will take each name (string) from mens_name(list of strings) and call the upper method for this string. then after finishing all names it will be saved in the new list mens_name_upper – Mohamed Abd El Raouf Feb 03 '14 at 23:26
0

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
scriptmonster
  • 2,741
  • 21
  • 29