Unique Element Extractor

  • Share this:

Code introduction


This function takes a list as input and returns a list containing all unique elements. It uses a set to track elements that have already been encountered.


Technology Stack : Set

Code Type : Function

Code Difficulty : Intermediate


                
                    
def unique_list(lst):
    seen = set()
    unique_lst = []
    for item in lst:
        if item not in seen:
            unique_lst.append(item)
            seen.add(item)
    return unique_lst                
              
Tags: