R
rh0dium
Hi all,
I have a simple list to which I want to append another tuple if
element 0 is not found anywhere in the list.
element = ('/smsc/chp/aztec/padlib/5VT.Cat',
'/smsc/chp/aztec/padlib',
'5VT.Cat', (33060))
element1 = ('/smsc/chp/aztec/padlib/5VT.Cat2',
'/smsc/chp/aztec/padlib',
'5VT.Cat2', (33060))
a = [ ('/smsc/chp/aztec/padlib/5VT.Cat',
'/smsc/chp/aztec/padlib',
'5VT.Cat', (33060)),
('/smsc/chp/aztec/padlib/padlib.TopCat%',
'/smsc/chp/aztec/padlib',
'padlib.TopCat%', (33204)),
('/smsc/chp/aztec/padlib/Regulators.Cat%',
'/smsc/chp/aztec/padlib',
'Regulators.Cat%', (33204))]
So my code would look something like this.
found = False
for item in a:
if item[0] == element[0]
found = True
break
if not found:
a.append(element)
But this is just ugly - Is there a simpler way to interate over all
items in a without using a found flag?
Thanks
I have a simple list to which I want to append another tuple if
element 0 is not found anywhere in the list.
element = ('/smsc/chp/aztec/padlib/5VT.Cat',
'/smsc/chp/aztec/padlib',
'5VT.Cat', (33060))
element1 = ('/smsc/chp/aztec/padlib/5VT.Cat2',
'/smsc/chp/aztec/padlib',
'5VT.Cat2', (33060))
a = [ ('/smsc/chp/aztec/padlib/5VT.Cat',
'/smsc/chp/aztec/padlib',
'5VT.Cat', (33060)),
('/smsc/chp/aztec/padlib/padlib.TopCat%',
'/smsc/chp/aztec/padlib',
'padlib.TopCat%', (33204)),
('/smsc/chp/aztec/padlib/Regulators.Cat%',
'/smsc/chp/aztec/padlib',
'Regulators.Cat%', (33204))]
So my code would look something like this.
found = False
for item in a:
if item[0] == element[0]
found = True
break
if not found:
a.append(element)
But this is just ugly - Is there a simpler way to interate over all
items in a without using a found flag?
Thanks