python - Check variable if it is in a list -


i new python, , wondering if there succinct way of testing value see if 1 of values in list, similar sql clause. sorry if basic question.

msupdate.updateclassificationtitle in (         'critical updates',         'feature packs',         'security updates',         'tools',         'update rollups',         'updates',         ) 

i.e, want write:

if msupdate.updateclassificationtitle in (         'critical updates',         'feature packs',         'security updates',         'tools',         'update rollups',         'updates'         ):       then_do_something() 

seems succinct enough, if you're using more once should name tuple:

titles = ('critical updates',     'feature packs',     'security updates',     'tools',     'update rollups',     'updates')  if msupdate.updateclassificationtitle in titles:       do_something_with_update(msupdate) 

tuples use parenthesis. if want list change square brackets. or use set, has faster lookups.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -