Extract Unique Elements from Iterables

  • Share this:

Code introduction


This function accepts an arbitrary number of iterable objects as arguments and returns a set containing all unique elements.


Technology Stack : Set (set)

Code Type : Function

Code Difficulty : Intermediate


                
                    
def unique_items(*args):
    seen = set()
    for arg in args:
        for item in arg:
            if item not in seen:
                seen.add(item)
    return seen                
              
Tags: