What python concept causes this result?

BologneseBandit

So I was studying for an exam and i made a simple function to review 'sequential processing' and then I made this function(s) that turn a string input of whitespaced numbers into a list and scan to find the highest, but my conditional seems to think 8 is greater than 20 and 23. Can someone tell my why this is?

def findMax(numberlist):
maxval = numberlist[0]
for i in numberlist[1:]:
    print("The value now is:\t",i,"\nThe max value is currently\t",maxval,"\n")
    if(i > maxval):
        maxval = i
print(maxval)
return maxval

def makeList(stringput):
    print(stringput)
    stringput = stringput.split(" ")
    for i in stringput[0:]:
        print("Value is:\t",i)
    return stringput

findMax(makeList(input("\nWhat test are to be sorted\n")))

This returned the result 8 from the input "1 20 8 21"

Edit:Sorry, new user .

Shadow

You're entering strings into python. That means that all sorting is happening alphabetically - not numerically.

For example, if you sorted the following two word alphabetically, which would you put first?

Apple

Bee

Apple right? Because A comes before B. Lets try again

8

23

It's going to be 23 - 8 is later in the 'alphabet'.

If you want to sort these properly, cast them all to ints first. Or use a library such as natsorted.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What causes this strange result in Python when assigning to values in a dictionary?

From Dev

What causes this strange result in Python when assigning to values in a dictionary?

From Dev

What is the value of boolean(True and False) in Python concept and shell concept?

From Dev

What causes this attribute error in python?

From Java

What are Mixins (as a concept)

From Dev

What is the concept of vruntime in CFS

From Dev

What is this concept of Pending Interrupts

From Dev

What is this concept of Pending Interrupts

From Dev

What is the concept of source in pulseaudio?

From Dev

What causes the "procedure has not been executed or has no result" error and how to prevent it?

From Dev

What should be result for -1%5 in python

From Dev

What causes Python's float_repr_style to use legacy?

From Dev

list of list concept in python

From Dev

Solution to turtle concept in Python

From Dev

List variable concept in python

From Dev

what exactly is the concept of vectors in opencv?

From Dev

What is the concept of Service Container in Laravel?

From Dev

What is Concept of Idempotent in RestFul WebApi?

From Dev

What is the concept of Ambassador in distributed systems?

From Dev

What is the concept to access JSON data?

From Dev

what exactly is the concept of vectors in opencv?

From Dev

iostat: what is exactly the concept of merge

From Dev

What is the concept of Ambassador in distributed systems?

From Dev

What is the equivalent concept of highstates with Ansible?

From Java

What causes [*a] to overallocate?

From Dev

What are the causes of RejctedExecutionException?

From Dev

InterruptedException : what causes it?

From Dev

What causes this performance drop?

From Dev

What causes "--- []" in rspec output?

Related Related

  1. 1

    What causes this strange result in Python when assigning to values in a dictionary?

  2. 2

    What causes this strange result in Python when assigning to values in a dictionary?

  3. 3

    What is the value of boolean(True and False) in Python concept and shell concept?

  4. 4

    What causes this attribute error in python?

  5. 5

    What are Mixins (as a concept)

  6. 6

    What is the concept of vruntime in CFS

  7. 7

    What is this concept of Pending Interrupts

  8. 8

    What is this concept of Pending Interrupts

  9. 9

    What is the concept of source in pulseaudio?

  10. 10

    What causes the "procedure has not been executed or has no result" error and how to prevent it?

  11. 11

    What should be result for -1%5 in python

  12. 12

    What causes Python's float_repr_style to use legacy?

  13. 13

    list of list concept in python

  14. 14

    Solution to turtle concept in Python

  15. 15

    List variable concept in python

  16. 16

    what exactly is the concept of vectors in opencv?

  17. 17

    What is the concept of Service Container in Laravel?

  18. 18

    What is Concept of Idempotent in RestFul WebApi?

  19. 19

    What is the concept of Ambassador in distributed systems?

  20. 20

    What is the concept to access JSON data?

  21. 21

    what exactly is the concept of vectors in opencv?

  22. 22

    iostat: what is exactly the concept of merge

  23. 23

    What is the concept of Ambassador in distributed systems?

  24. 24

    What is the equivalent concept of highstates with Ansible?

  25. 25

    What causes [*a] to overallocate?

  26. 26

    What are the causes of RejctedExecutionException?

  27. 27

    InterruptedException : what causes it?

  28. 28

    What causes this performance drop?

  29. 29

    What causes "--- []" in rspec output?

HotTag

Archive