Write a Python program prints out the unique elements of a list lst in a sorted manner (i.e it removes duplicates from the list). For example, if list is [10,20,30,20,10,50,60,40,80,50,40], the output should be [10, 20, 30, 40, 50, 60, 80].?
lst = eval(input("Enter a list: ")) # go through all the elements of the list and create a list without duplicates result = [] # create an empty list as result for item in lst: # go through each item in list if item not in result: # if that item is not already in result list result.append(item) # then add it to the result list result.sort() # sort the list print(result) # print the list
Get Answers For Free
Most questions answered within 1 hours.