+ 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"] ?
19 Antworten
+ 10
Sort sorts ascendingly.
[1, 2, 3]
[65, 90]
['A', 'a']
+ 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 😅
+ 7
Oh...Omg...i just... realised how stupid my question was !😅😂...Im sorry guys...got confused a bit 😂
+ 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'.
+ 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.
+ 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...😆
+ 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,
+ 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
+ 2
Finally!😄
+ 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
+ 1
Hey are u kidding?
2 > 1
So how do you think [2,1] is sorted.
was irritated tbh.
+ 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!
+ 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.
+ 1
Anurag Mondal The only stupid question is one not asked.
0
Did you know the ascii values of a-z and A-Z? Or even how sort function works?
0
Obviously a is greater than A
0
Or do you think 90>65(a>A) should return false?😂
- 5
learn Web development in Hindi https://www.youtube.com/channel/UCJuO5LL2iLWewVqszbFojLg
- 6
امكتالاةة