-2
mens_name = ['Bob', 'Frank', 'John', 'Rob', 'Eric', 'Dan', 'Doug']
current_name = raw_input('Please enter a name: ')
if current_name == mens_name[0 or 1 or 2 or 3 or 4 or 5 or 6 or 7] or mens_name[0].upper():
    print 'I know that name.\n'

is there an easier way of doing this, or do I have put all of those or's?

Thanks, G

Patsy Issa
  • 11,113
  • 4
  • 55
  • 74
user3264459
  • 15
  • 1
  • 4
  • 3
    Note, that `0 or 1 or 2 or 3 or 4 or 5 or 6 or 7` is always `1`. And `current_name == mens_name[0 or 1 or 2 or 3 or 4 or 5 or 6 or 7] or mens_name[0].upper()` is always `True`, because `mens_name[0].upper()` is `True`. – awesoon Feb 03 '14 at 22:00

1 Answers1

6

Use in keyword:

if current_name in mens_name:
ndpu
  • 22,225
  • 6
  • 54
  • 69
  • 1
    It is not only easier, it actually works, unlike your snippet. But soon pointed this out in a comment. – Hyperboreus Feb 03 '14 at 22:01
  • Pleas accept the answer if you consider it helpful. – Visgean Skeloru Feb 03 '14 at 22:10
  • mens_name = ['Bob', 'Frank', 'John', 'Rob', 'Eric', 'Dan', 'Doug'] current_name = raw_input('Please enter a name: ') if current_name in mens_name or current_name in mens_name.upper(): print 'I know that name.' Do i have to split this into two? – user3264459 Feb 03 '14 at 22:14
  • @user3264459 you cant call upper on list instance but can on string: `if name.upper() in mens_name:` – ndpu Feb 03 '14 at 22:33
  • so would I create a new string like mname = mens_name? – user3264459 Feb 03 '14 at 22:57
  • @user3264459 here answer to you question, if you need list with upper case names:http://stackoverflow.com/a/21539256/1099876 – ndpu Feb 03 '14 at 23:02