Member-only story

Interview question: Remove duplicate items from a list

Crystal X
2 min readApr 27, 2023

--

One Python coding interview question that might crop up is how to remove duplicate items from a list. I have very quickly thought of three ways to easily accomplish this task in Python, and I will show them:-

  1. Create a dictionary to remove duplicate items from a list.
  2. Create a set to remove duplicate items from a list.
  3. Create a temporary list to hold all list items that are not duplicate.

Removing duplicate items from a list using the dictionary method:-

  1. Create a dictionary, using the List items as keys. This will automatically remove any duplicates because dictionaries cannot have duplicate keys.
  2. Convert the dictionary back into a list.
  3. Print the list to demonstrate the result.

Removing duplicate items from a list using the set method:-

  1. Create a set from the list items. This will automatically remove any duplicates because sets do not allow any duplicate values.
  2. Convert the set back to a list.
  3. Print the list to demonstrate the result.

Removing items from a list using the temporary list method:-

  1. Create a temporary list, temp_list, which is a blank…

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet