Eliminate Duplicates of a List (Python)

I have a list of lists and need to eliminate all lists that have the same 3rd element, and save 1.

For example:

x=[[1,2,3],[1,3,3],[5,6,3],[2,4,6],[8,5,9],[10,5,9]]

could turn into:

x=[[1,2,3],[2,4,6],[8,5,9]]

I've attempted a solution that eliminates all lists that have the same 2nd index using lambda, but I don't know how to save one of each element like set() does--I just get:

x=[[2,4,6]]

Answers


Python sets should still work for you:

>>> seen = set()
>>> result = []
>>> for s in x:
    e = s[2]
    if e not in seen:
        result.append(s)
        seen.add(e)


>>> result
[[1, 2, 3], [2, 4, 6], [8, 5, 9]]

Need Your Help

Compressing fonts for using in web

css css3 font-face webfonts

Can fonts be compressed someway before using as webfonts? I have a font file which is 150kB. Is it possible to compress it down.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.