Abc and 123

hi there,

so i was going trough the basic algorithms part of computer science, and i was asked to make a function that finds the max value within a linked list, so i made the function without really seeing the test code that was already provided in the exercise. :

then when i hit run and saw the test code output, i saw that one of the test linked lists was made with letters instead of numbers and it works the same

and my question is, do letters work with operands the same way numbers do? like a < z = True
i probably missed one of the bases or i cant remember but this bugged me

From: 6. Expressions — Python 3.11.4 documentation

  • Strings (instances of str) compare lexicographically using the numerical Unicode code points (the result of the built-in function ord()) of their characters. [3]
print("A" < "D") # True
print("A" < "a") # True
print("D" < "a") # True
print(ord("D"))  # 68
print(ord("A"))  # 65
print(ord("a"))  # 97

There is a Codecademy exercise
showing how the sort() method can be used to sort a list of strings.

However, it doesn’t do natural sorting. See this post for a little more detail: FAQ: Working with Lists in Python - Sorting Lists I - #38 by mtrtmk

print(42 <  221) # True
print('42' < '221') # False