if there are same elements in the list, how can i take them away and make the list unique..... somethings like array_unique in PHP.... i have consult this web site, but it doesn't talk about it
about array
Collapse
X
-
Here's one way:
If you are using Python 2.4 or higher:Code:>>> some_list = [1,1,1,2,2,2,3,3,3] >>> unique_list = [] >>> for item in some_list: ... if item not in unique_list: ... unique_list.append(item) ... >>> unique_list [1, 2, 3] >>>
A set can contain only unique elements. A set can be converted back to a list.Code:>>> set(some_list)
-
I would do something like this:
Code:a = [1,1,1,1,2,3,3,3,3,4] b = {} for aa in a: b[aa] = 1 print b.keys()if there are same elements in the list, how can i take them away and make the list unique..... somethings like array_unique in PHP.... i have consult this web site, but it doesn't talk about it
http://www.java2s.com/Code/Python/List/CatalogList.htmComment
Comment