-3

I tried the following code, and the results are given below that. I know of other methods, but I'd like to know why this one fails.

l=list(input("Enter a list:"))

for a in l:
    for b in l:
        if a>=b:
            break
        else:
            print(a,l.index(a))

Result:

Enter a list:3,2,4,5
, 1
2 2
, 1
, 1

Green05
  • 319
  • 1
  • 8
  • 1
    Every single character in your input including spaces and commas will be an item of the list if you cast it like that. – Klaus D. Jun 08 '20 at 16:40

1 Answers1

-1

Replace first line with this:

l=eval("["+input("Enter a list:")+"]")
Green05
  • 319
  • 1
  • 8