-3

how can I use python to sort() list by letters from Z to A?

names = ["Adam","Alex","Mariah","Martine","Columbus"]

*beginner

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
in_process
  • 9
  • 1
  • 3

1 Answers1

2

By telling the sorted() function or list.sort() method to reverse the output:

sorted(names, reverse=True)  # returns new list
names.sort(reverse=True)     # sorts list in place
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 2
    Is it a good practice to mark a question as duplicate and answer it at the same time? – Sait Aug 16 '15 at 00:50
  • @Sait: it is good practice to close a question as a duplicate once you are aware of there being a good duplicate target. I wasn't aware of the duplicate until River flagged it, or I would have duped it sooner. – Martijn Pieters Aug 16 '15 at 00:52
  • @MartijnPieters oddly enough that got my flag disputed somehow... – River Aug 16 '15 at 06:07
  • 1
    @River actually that was because the post was also in the Triage queue and your flag was disputed when the last *Looks Good* vote came in. I'll probably report that as an issue. – Martijn Pieters Aug 16 '15 at 11:18