[Python] Remove duplicate elements from list

Source: Internet
Author: User
Lists = [A, M, m, MB] Print list (set (lists))

Set () is a built-in data type "collection type" that is unordered and has a unique value. So the result of the set () is to go to the set and directly away from the duplicated elements, and then list () to return the collection back to the type. However, set () will break the order, and if you want to keep the sort, list (set (lists)) can be changed to sorted (set (lists), Key=lists.index)

------------------------------------------------------------

We need to sort the list, Python provides two methods
To sort the given list L.
Method 1. Sort with the member function of the list
Method 2. Sort with the built-in function sorted (starting from 2.4)

?

1 2 3 4 5 6 7 8 9 10 11-12

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.