Sep-26-2021, 07:18 AM
(This post was last modified: Sep-26-2021, 07:24 AM by OmegaRed94.)
Good day, Dear Pythonistas
I have the following problem: Given a list, we should write a function that returns sorted in descending order unique squares of numbers contained in this list
I have got the solution in the following way, it works correctly:
I have the following problem: Given a list, we should write a function that returns sorted in descending order unique squares of numbers contained in this list
I have got the solution in the following way, it works correctly:
def squares_list(l): for elem in l: empty_list.extend(elem) new_list=list(set(empty_list)) new_list.sort(reverse=True) squares=[i**2 for i in new_list] return squares print(squares_list([[1, 2], [3], [4], [3, 1]]))Could you, please, suggest, how I could write this code or the solution in the shortest possible optimal way (a smaller number of characters)?