Unique elements in list

Python, List · Sep 15, 2020

Returns the unique elements in a given list.

  • Create a set from the list to discard duplicated values, then return a list from it.
def unique_elements(li):
  return list(set(li))
unique_elements([1, 2, 2, 3, 4, 3]) # [1, 2, 3, 4]

More like this

  • Count grouped elements

    Groups the elements of a list based on the given function and returns the count of elements in each group.

    Python, List · Nov 2, 2020

  • Group list elements

    Groups the elements of a list based on the given function.

    Python, List · Nov 2, 2020

  • Find matching index

    Finds the index of the first element in the given list that satisfies the provided testing function.

    Python, List · Nov 2, 2020