0

Does python use the same sorting method in all cases? For example, a few cases:

s = "some text here"
l = ["some", "items", "here"]

sorted(s)
sorted(l)
sorted(s, key=lambda x: ord('l')-ord(x))
l.sort()

Is it always the same? If so, which algorithm(s) is used for the above?

David542
  • 104,438
  • 178
  • 489
  • 842
  • What is the point of this question? It isn't very clear. Which of the above outputs do you consider problematic or indicative of Python using multiple sorting algorithms under the hood? – John Coleman Sep 11 '19 at 01:08
  • @JohnColeman I'm just curious actually, no problem. – David542 Sep 11 '19 at 01:11
  • 1
    Curiosity is good, but in that case @Grismar is probably correct that it is a duplicate – John Coleman Sep 11 '19 at 01:12
  • @Daved542 can you please indicate if the question linked as a duplicate does in fact answer your question? Otherwise, please amend your question to be more specific, so we can help provide an answer - curiosity is fine as a reason, the question is valid, but I think it has already been answered on SO. – Grismar Sep 11 '19 at 01:49
  • @Grismar sure that seems like a good link, though a lot of the details are buried in the "link to cython". Thanks for the link. – David542 Sep 11 '19 at 01:57
  • 1
    It also has a comment by Tim Peters, the actual author of timsort, which is the one-word answer to your question. https://en.wikipedia.org/wiki/Timsort – Grismar Sep 11 '19 at 02:00

0 Answers0