how to make this situation return this result?

Peter Otten __peter__ at web.de
Sat Jul 1 09:10:14 EDT 2017


Ho Yeung Lee wrote:

> just want to compare tuples like index (0,1), (0,2), (1,2) without
> duplicate
>  such as (2,0), (1,0) etc


Consider (frozen)sets:

>>> {1, 2} == {2, 1}
True
>>> unique_items = {frozenset((a, b)) for a in range(3) for b in range(3)}
>>> unique_items
set([frozenset([0]), frozenset([1, 2]), frozenset([0, 2]), frozenset([1]), 
frozenset([2]), frozenset([0, 1])])


> On Saturday, July 1, 2017 at 7:00:17 PM UTC+8, Peter Otten wrote:
>> Ho Yeung Lee wrote:
>> 
>> > finally i searched dict.values()[index] solved this
>> 
>> That doesn't look like a good solution to anything -- including "this",
>> whatever it may be ;)
>> 
>> If you make an effort to better explain your problem in plain english
>> rather than with code examples you are likely tho get better answers.





More information about the Python-list mailing list