#I am confused.
24 messages · Page 1 of 1 (latest)
"more indexes"?
min and max on a list of strings just perform alphabetical comparisons on the strings
len= length of the list in your case
Kinda confusing a lil yes, maybe share your script full?
my output:
3
Banane
mohrrübe
mylist=['Banane', 'Schokolade', 'mohrrübe']
print(len(mylist))
print(min(mylist))
print(max(mylist))
so you do smth else? xD
ahhhh he is not looking up for the length of chars in this.
he is looking up for the number value. But of the first letter only 😄
here my script that explains it:
mylist=['Banane', 'Schokolade', 'mohrrübe']
print(len(mylist))
print(min(mylist))
print(max(mylist))
for ele in mylist:
total = sum(map(ord, ele))
first_ascii = ord(ele[0])
print(f"{ele} ascii summed: {total}, ascii first letter: {first_ascii}")
out:
3
Banane
mohrrübe
Banane ascii summed: 581, ascii first letter: 66
Schokolade ascii summed: 1021, ascii first letter: 83
mohrrübe ascii summed: 1003, ascii first letter: 109
basically its checking for the first letters ascii value,
the "m" has bigger value then all capital letters ("B", "S")
but "b" and "s" would have higher values 😄
Its just capital letters hae lower ascii value then lowercase letters.
So that explains the srting you have there 🙂
Nope, it's doing alphabetical ordering
but lowercase have a bigger value here
if you want it to use the length of the values you'd have to pass in a custom key, e.g. print(min(mylist, key=lambda v: len(v)))
It's not only the first character
If the first characters differ you can implement full ordering using only that character, if it's the same you also have to take into account the second or third etc. characters
Ok I got it thank you guys soo much:)
Noted.
Sorry to bother you but I just tested it with "Mohrrübe" and not "mohrrübe but it now says that the first letter of Schokolade has a higher ascii value than "Banane" even though "B" is in front of "S" in alphabetical order.
Here:
Oh and 1 more thing, why would "S" have a higher ascii value than "M" if its going off of alphabetical order"
Troll, just do key=len
😠
But then they don't get to learn about how key works with custom functions 😠
Hehehe