Python Forum
Descending order unique squares
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Descending order unique squares
#1
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:
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)?
Reply


Messages In This Thread
Descending order unique squares - by OmegaRed94 - Sep-26-2021, 07:18 AM
RE: Descending order unique squares - by deanhystad - Sep-26-2021, 08:09 AM
RE: Descending order unique squares - by OmegaRed94 - Sep-26-2021, 08:33 AM
RE: Descending order unique squares - by ndc85430 - Sep-26-2021, 08:58 AM
RE: Descending order unique squares - by deanhystad - Sep-26-2021, 09:00 AM
RE: Descending order unique squares - by OmegaRed94 - Sep-26-2021, 09:08 AM
RE: Descending order unique squares - by ndc85430 - Sep-26-2021, 04:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  a generator that computes squares of first 20 natural numbers mdshamim06 1 9,014 Oct-01-2019, 10:38 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020