Quick actions

cmd+k|ctrl+k

Navigation

Languages

RemoveDuplicates

Snippet info

Language

Python

Visibility

public

Author

arthurpc02

Created

2024-08-02T20:34:52.933366Z

Updated

2024-08-02T21:13:00.254879Z

# Basic Python Syntax and Data Structures

# Question: Write a Python function that takes a list of integers and returns a list with only the unique elements (i.e., remove duplicates).
# Example: Input: [1, 2, 2, 3, 4, 4, 5], Output: [1, 2, 3, 4, 5].

# inputs: list of integers
# outputs: list of integers (no dupicates)



def removeDuplicatesFromIntegerArray(int_array):
    
    array_noDuplicates = []
    duplicatesBuffer = dict()
    
    for element in int_array:
        element_str = str(element)
        if element_str not in duplicatesBuffer:
            duplicatesBuffer[element_str] = True
            array_noDuplicates.append(element)
            
        # print(element)
    
    return array_noDuplicates
    
def main():
    Array1 = [2, 1, 2, 2, 2, 3, 4, 5]
    print(removeDuplicatesFromIntegerArray(Array1))

if __name__ == "__main__":
    main()
INFO