#I am confused.

24 messages · Page 1 of 1 (latest)

brisk tulip
#

I'm German but you don't have to understand the words.
['Banane', 'Schokolade', 'mohrrübe'] is my list.
I'm confused because "Schokolade" has way more indexes than "mohrrübe"

knotty ember
#

"more indexes"?

min and max on a list of strings just perform alphabetical comparisons on the strings

brisk tulip
#

Idk man i mean like more letters

#

Which is what it’s going off of right?

marsh geyser
#

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 🙂

knotty ember
marsh geyser
#

but lowercase have a bigger value here

knotty ember
#

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)))

knotty ember
brisk tulip
#

Ok I got it thank you guys soo much:)

brisk tulip
#

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.

#

Oh and 1 more thing, why would "S" have a higher ascii value than "M" if its going off of alphabetical order"

marsh geyser
#

m
nopqr
s

thats why

#

ascending = aufsteigend in german 😉

knotty ember
#

But then they don't get to learn about how key works with custom functions 😠

low plume