check if the values are prensent in a list of values

Emile van Sebille emile at fenx.com
Tue Sep 9 14:13:45 EDT 2008


flit wrote:
> Hello All,
> 
> I will appreciate the help from the more skillfull pythonistas..
> 
> I have a small app that generates a sequence like
> 
> 00341
> 01741
> 03254

Consider using a dict with sorted tuple keys, eg

d = {}

for seq in ['00341','01741','03254']:
     ky = list(seq)
     ky.sort()
     d[tuple(ky)] = None


then d.keys() are the unique combinations.

HTH,

Emile



> 
> This values I am putting in a list.
> 
> So I have a list = [00341,01741,03254]
> 
> after the programs find the sequence 03401 this sequence is "new" so
> it appends on the list. But I want to avoid that as the   values are
> already on the first sequence of the list (00341).
> If I try to  use a "in" statement it will give false. as 00341 is
> different from 00341 (but for my goal not..)
> 
> 
> How can I check against this list and avoid to put "different"
> sequences but same values?
> 
> as 34100 --> dont append on the list
> 14300 ---> dont append on the list
> 05321 --> append to the list.
> 
> Am I doing some conceptual error using lists?
> There is a better approach?
> 
> Thanks
> 
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list