Correct way to do 'if list in list' python -
i taught myself python little while ago , find myself continually doing piece of logic...
if element of lista in listb blah blah...
i code as:
for in lista: if in listb:
given frequency come across assume there must more efficient way of coding this?
thanks in advance.
yes, any()
function :).
if any(i in listb in lista):
this assuming want "do something"
once. if want i
(if in listb
), use for-loop have done.
any(i in listb in lista)
. pretty equivalent to:
for in lista: if in listb: return true return false
Comments
Post a Comment