Tino Dai wrote: > Hi there, > > I am wondering about a short cut to doing this. Let's say that we > have an array: > > dbs= ['oracle','mysql','postgres','infomix','access'] > > and we wanted to do this: > > if 'oracle' in dbs or 'mysql' in dbs or 'bdb' in dbs: > <... do something ...> > > Is there a short way or writing this? Something like > ('oracle','mysql','bdb') in dbs
I don't think there is a shortcut with lists. You could write any(db in dbs for db in ('oracle','mysql','bdb')) which at least lets you use a list for the targets, or if [ db for db in ('oracle','mysql','bdb') if db in dbs ]: With sets you can write dbs= set(['oracle','mysql','postgres','infomix','access']) if dbs.intersection(('oracle','mysql','bdb')): Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor