How to check for the presence of an item in a Python tuple without encountering a ValueError? -


for'ing on tuples consisting of (spendcampaign, adset, adcontent) (each value changing on each loop, want catch when last item in tuple same last item in tuple in saved mapping oldadmapping (a tuple of tuples).

if adcontent == oldadmapping[oldadmapping.index((spendcampaign, adset, adcontent))][2] 

i see breaks down valueerror (and equality check doesn't executed) whenever (spendcampaign, adset, adcontent) tuple not exist in oldadmapping.

for dicts, have has_key() function allows check if key in dict while avoiding keyerror if it's not. there similar tuples? if not, what's best way of checking presence of item in tuple wuthout encountering valueerror?

you validate if tuple contains it:

if (spendcampaign, adset, adcontent) in oldadmapping:     index = oldadmapping.index((spendcampaign, adset, adcontent)) 

and in condition use index

if adcontent == oldadmapping[index][2]:     ... 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -