-1

I'm creating a bubble sort program and need need the raw_input list to be integers.

alist=int(raw_input('Enter list of numbers---->')
print(alist)
for k in range(0,5):
    for i in range(0,5): 
        if alist[i]>alist[i+1]:
            swap=alist[i]
            alist[i]=alist[i+1]
            alist[i+1]=swap
            print(alist)
print(alist)
davidism
  • 121,510
  • 29
  • 395
  • 339
oad996
  • 11
  • 1

1 Answers1

0

I don't know what you trying to achieve but to get a list of numbers from raw_input try this.

list_input = raw_input('Enter list of numbers----> ')

# Using list comprehension separate the string by commas, then convert to an integer.
int_list = [int(i) for i in list_input.split(',')]

print int_list
Brandon Nadeau
  • 3,568
  • 13
  • 42
  • 65
  • 1
    visually shadowing a builtin via prepending an underscore... I'm not a fan. I'd highly recommend a more descriptive variable name: `input_as_string` for example. – TemporalWolf Sep 19 '17 at 19:12
  • good point, I'm getting back into coding, forgot about basic grammatic syntax. Thank you – Brandon Nadeau Sep 19 '17 at 19:16