+ 2
What is the code for this test ?
You are required to complete the function unique_list(l). where "l" is a list of numbers. the function is expected to return the unique numbers in that list. Example: input : [1,1,1,2,2,3,3,3,3,4,5,5,6] output: [1,2,3,4,5,6] you are not allowed to change the variable names or their values or edit any other code, except the function's body, doing so may jeopardize your evaluation In [ ]: no_list = [22,22,2,1,11,11,2,2,3,3,3,4,5,5,5,55,55,66] def unique_list(l): #complete the function's body to return the unique list of numbers print(unique_list(no_list))
3 Antworten
+ 2
This code no work ,answer start
In [ ]:
no_list = [22,22,2,1,11,11,2,2,3,3,3,4,5,5,5,55,55,66]
def unique_list(l):
#complete the function's body to return the unique list of numbers
print(unique_list(no_list))
+ 2
In [ ]:
no_list = [22,22,2,1,11,11,2,2,3,3,3,4,5,5,5,55,55,66]
def unique_list(l):
already = ""
result = []
for x in l:
if x == already:
pass
else:
result.append(x)
already = x
print(result)
unique_list(no_list)
0
You might try this,
Convert your list to set and then again set to list, it'll remove all duplicates.
But I'm not sure whether by doing this the elements will remain in the same alignment or not.