A question about Sorting of strings. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

A question about Sorting of strings.

If "a">"A" returns True Then suppose there is a list b=["a", "A"] Why does b.sort() returns ["A", "a"] ?

8th Apr 2020, 6:19 PM
Anurag Mondal
Anurag Mondal - avatar
19 Answers
+ 10
Sort sorts ascendingly. [1, 2, 3] [65, 90] ['A', 'a']
8th Apr 2020, 7:25 PM
HonFu
HonFu - avatar
+ 9
Yah...I am learning four different languages presently in four different platforms 😅 Im very new to solo learn... haven't even been a week since I started learning all these.....its such a huge community here😅..pardon me for such absurd question 😅
8th Apr 2020, 8:31 PM
Anurag Mondal
Anurag Mondal - avatar
+ 7
Oh...Omg...i just... realised how stupid my question was !😅😂...Im sorry guys...got confused a bit 😂
8th Apr 2020, 8:24 PM
Anurag Mondal
Anurag Mondal - avatar
+ 7
Don't beat yourself up though. 😉 If you think about it, it is a bit funny that 'A', although capital, is not greater than 'a'.
8th Apr 2020, 8:36 PM
HonFu
HonFu - avatar
+ 6
Obviously a is greater than A thats why it is returning true in the if condition and as it is greater, its also getting placed at the 1th index.
8th Apr 2020, 8:25 PM
Anurag Mondal
Anurag Mondal - avatar
+ 4
HonFu that maybe the very reason which was playing with my brain forcing me to think that a should come first😅...I was justifying my point so confidently that if a is bigger, why is A getting placed first? Lol...😆
8th Apr 2020, 8:54 PM
Anurag Mondal
Anurag Mondal - avatar
+ 3
Four different languages in four platform , that's great! When I started whatever time I got I just learned python for 6 months and practised a lot,
8th Apr 2020, 9:00 PM
Abhay
Abhay - avatar
+ 3
Strings are stored as ASCII Unicode, sort() function recognizes "A" as ASCII hex 0041 and "a" as ASCII hex 0061. Hence "A" will be before "a" , as in 0041 hex before 0061 hex. "a" > "A" is true since 61 hex>41 hex or if you prefer decimal 97 dec > 65 dec
10th Apr 2020, 7:06 PM
Radu Purcel
+ 2
Finally!😄
8th Apr 2020, 8:25 PM
Abhay
Abhay - avatar
+ 2
Happens when you are in rush or trying to learn a lot in small time ,i have learned rest is equally important for complete concentration
8th Apr 2020, 8:26 PM
Abhay
Abhay - avatar
+ 1
Hey are u kidding? 2 > 1 So how do you think [2,1] is sorted. was irritated tbh.
8th Apr 2020, 6:54 PM
Oma Falk
Oma Falk - avatar
+ 1
Doesn't sort returns in ascending order ?90>65,so a>A,and so ["A","a"]🤔 or am I missing something ,or is it descending order ?I have to ask these questions since two ppl liked your question!
8th Apr 2020, 7:11 PM
Abhay
Abhay - avatar
+ 1
Yes I do know it...what I meant in my question is that although it shows that a is bigger than A...then why is A getting placed first when I am sorting the list?...it should sort in ascending order right? And according to the Ascii value the sort is correct and thats what I was expecting...but then why is it returning true when im comparing weather a is > A or not?...this is my main point of confusion. My main concern is about the condition returning true.
8th Apr 2020, 8:20 PM
Anurag Mondal
Anurag Mondal - avatar
+ 1
Anurag Mondal The only stupid question is one not asked.
10th Apr 2020, 4:05 PM
Paul K Sadler
Paul K Sadler - avatar
0
Did you know the ascii values of a-z and A-Z? Or even how sort function works?
8th Apr 2020, 7:15 PM
Abhay
Abhay - avatar
0
Obviously a is greater than A
8th Apr 2020, 8:21 PM
Abhay
Abhay - avatar
0
Or do you think 90>65(a>A) should return false?😂
8th Apr 2020, 8:22 PM
Abhay
Abhay - avatar
10th Apr 2020, 5:51 AM
anil sen
anil sen - avatar
- 6
امكتالاةة
9th Apr 2020, 12:36 PM
كوزي زين
كوزي زين - avatar