Python example of a method that simply deletes the same element in a list

  • 2020-06-03 07:17:11
  • OfStack

This article example shows how Python can simply delete the same elements from a list. To share for your reference, specific as follows:

Remove duplicate elements from the list, very simple, directly on the code:


a = [11, 21, 3, 4, 3, 2, 5]
b = list(set(a))
print(a)
print(b)

Operation results:


E:\Program\Python>d.py
[11, 21, 3, 4, 3, 2, 5]
[2, 3, 4, 5, 11, 21]

You see, there are no repeating elements. But, at the same time, the elements in the result are sorted from smallest to largest!

PS: Here are a few more repetition tools you can use:

Online tool for removing duplicates:
http://tools.ofstack.com/code/quchong

Online text de-duplication tools:
http://tools.ofstack.com/aideddesign/txt_quchong

More Python related content interested readers to view this site project: "Python list (list) skills summary", "Python coding skills summary", "Python data structure and algorithm tutorial", "Python function using techniques", "Python string skills summary", "Python introduction and advanced tutorial" and "Python file and directory skills summary"

I hope this article has been helpful in Python programming.


Related articles: