Exercise: Function: uniq()

Write a function uniq() that takes a sequence as input. It returns a list with duplicate elements removed, and where the contained elements appear in the same order that is present in the input sequence. The input sequence remains unmodified.

The program structure could be something like follows …

def uniq(l):
    # ... here a miracle has to happen ...
    return ... # the uniq-ified list

input_list = [2, 3, 1, 10, 3, 3, 1, 10, 5, 2]
output_list = uniq(input_list)

for element in output_list:
    print(element)

The expected program output is as follows:

$ python uniq.py
2
3
1
10
5

Dependencies

cluster_python Python Programming: From Absolute Beginner to Advanced Productivity cluster_python_basics Python: The Language Fundamentals cluster_python_exercises Exercises cluster_python_exercises_legacy Exercises (Legacy) python_basics_python_0160_boolean Boolean python_basics_python_0150_datatypes_overview Datatypes python_basics_python_0160_boolean->python_basics_python_0150_datatypes_overview python_basics_python_0120_helloworld Hello World python_basics_python_0110_blahblah Blahblah python_basics_python_0120_helloworld->python_basics_python_0110_blahblah python_basics_python_0130_syntax_etc Syntax etc. python_basics_python_0130_syntax_etc->python_basics_python_0120_helloworld python_basics_python_0139_commandline_argv Commandline Arguments (sys.argv) python_basics_python_0139_commandline_argv->python_basics_python_0130_syntax_etc python_basics_python_0125_running Running Python Programs python_basics_python_0139_commandline_argv->python_basics_python_0125_running python_basics_python_0150_datatypes_overview_compound Compound Datatypes python_basics_python_0150_datatypes_overview_compound->python_basics_python_0150_datatypes_overview python_basics_python_0193_while while Loops python_basics_python_0193_while->python_basics_python_0160_boolean python_basics_python_0170_if The if Statement python_basics_python_0193_while->python_basics_python_0170_if python_basics_python_0200_sequential_types Sequential Datatypes python_basics_python_0200_sequential_types->python_basics_python_0150_datatypes_overview_compound python_basics_python_0270_functions Functions python_basics_python_0270_functions->python_basics_python_0150_datatypes_overview python_basics_python_0140_variables Variables python_basics_python_0270_functions->python_basics_python_0140_variables python_basics_python_0125_running->python_basics_python_0120_helloworld python_basics_python_0225_range The range Function python_basics_python_0225_range->python_basics_python_0200_sequential_types python_basics_python_0220_for for Loops python_basics_python_0225_range->python_basics_python_0220_for python_basics_python_0150_datatypes_overview->python_basics_python_0140_variables python_basics_python_0140_variables->python_basics_python_0130_syntax_etc python_basics_python_0170_if->python_basics_python_0160_boolean python_basics_python_0220_for->python_basics_python_0193_while python_basics_python_0220_for->python_basics_python_0200_sequential_types python_exercises_legacy_while_primeness Exercise: Primeness (while) python_exercises_legacy_while_primeness->python_basics_python_0139_commandline_argv python_exercises_legacy_while_primeness->python_basics_python_0193_while python_exercises_legacy_cmdline_digit Exercise: Digit to English Word python_exercises_legacy_while_primeness->python_exercises_legacy_cmdline_digit python_exercises_legacy_max_numbers_function Exercise: Determine Maximum of Two Numbers (Function) python_exercises_legacy_max_numbers_function->python_basics_python_0270_functions python_exercises_legacy_max_numbers Exercise: Determine Maximum of Two Numbers python_exercises_legacy_max_numbers_function->python_exercises_legacy_max_numbers python_exercises_legacy_for_primeness Exercise: Primeness (for) python_exercises_legacy_max_numbers_function->python_exercises_legacy_for_primeness python_exercises_legacy_mixed_list_executable Exercise: Mixed List (Executable Program) python_exercises_legacy_mixed_list_executable->python_basics_python_0160_boolean python_exercises_legacy_mixed_list_executable->python_basics_python_0120_helloworld python_exercises_legacy_mixed_list_executable->python_basics_python_0150_datatypes_overview_compound python_exercises_legacy_mixed_list_executable->python_basics_python_0150_datatypes_overview python_exercises_legacy_mixed_list_executable->python_basics_python_0140_variables python_exercises_legacy_mixed_list_interactive Exercise: Mixed List (Interactive Interpreter) python_exercises_legacy_mixed_list_executable->python_exercises_legacy_mixed_list_interactive python_exercises_legacy_cmdline_digit->python_basics_python_0120_helloworld python_exercises_legacy_cmdline_digit->python_basics_python_0139_commandline_argv python_exercises_legacy_cmdline_digit->python_basics_python_0150_datatypes_overview_compound python_exercises_legacy_cmdline_digit->python_basics_python_0150_datatypes_overview python_exercises_legacy_max_numbers->python_basics_python_0139_commandline_argv python_exercises_legacy_max_numbers->python_basics_python_0140_variables python_exercises_legacy_max_numbers->python_basics_python_0170_if python_exercises_legacy_max_numbers->python_exercises_legacy_mixed_list_executable python_exercises_legacy_for_primeness->python_basics_python_0225_range python_exercises_legacy_for_primeness->python_basics_python_0220_for python_exercises_legacy_for_primeness->python_exercises_legacy_while_primeness python_exercises_legacy_uniq_function Exercise: Function: uniq() python_exercises_legacy_uniq_function->python_basics_python_0150_datatypes_overview_compound python_exercises_legacy_uniq_function->python_basics_python_0270_functions python_exercises_legacy_function_primeness Exercise: Primeness (Function) python_exercises_legacy_uniq_function->python_exercises_legacy_function_primeness python_exercises_legacy_function_primeness->python_basics_python_0139_commandline_argv python_exercises_legacy_function_primeness->python_basics_python_0270_functions python_exercises_legacy_function_primeness->python_exercises_legacy_max_numbers_function python_exercises_legacy_mixed_list_interactive->python_basics_python_0160_boolean python_exercises_legacy_mixed_list_interactive->python_basics_python_0150_datatypes_overview_compound python_exercises_legacy_mixed_list_interactive->python_basics_python_0150_datatypes_overview python_exercises_legacy_mixed_list_interactive->python_basics_python_0140_variables