2

Here, the array has two dimensions(characters and numbers) and i wanna get the unique items by only respecting second dimension which are numbers in myList below. I have done this by using an additional list(a_list), but i am looking for a better way.

myList=[]

myList.append(("a",0))
myList.append(("b",0))
myList.append(("b",0))
myList.append(("a",1))
myList.append(("a",1))

distinctmyList =[]
a_list=[]

for  i in myList:
    a_list.append(i[1])
distinctmyList.append(list(set(a_list)))
print distinctmyList

The output:

[[0, 1]] 

which are unique items of myList by respecting second items which are numbers(0s and 1s).

4

3 に答える 3