-1
#!/bin/python
def insertionSort(list):

for i in xrange(1,len(list)):
    value=list[i]
    pos=i
    while pos>0 and value <list[pos-1]:           
        list[pos]=list[pos-1]
        print list
        pos-=1
    list[pos]=value
return list
m = input()
list = [int(i) for i in raw_input().strip().split()]
insertionSort(list)

This is my output:

[2, 4, 6, 8, 8]
[2, 4, 6, 6, 8]
[2, 4, 4, 6, 8]

But I need the same result but without brackets and commas.

2 4 6 8 8
2 4 6 6 8
2 4 4 6 8
2 3 4 6 8

I tried to use print ' '.join(list) but still didn't work.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
  • Please do not name your variables `list`. It's for your own good; this will bite you, hard, if you continue to shadow built-in names. Also, do not use `input` in Python 2; it's equivalent to `eval(raw_input())` and it's a source of serious security and stability issues. I don't see what `m` is even used for, but consider using `raw_input` and an appropriate constructor (or `ast.literal_eval` if necessary), anything but `eval` (implicit or otherwise). – ShadowRanger Sep 30 '16 at 07:34

3 Answers3

2

Replace:

print list

With:

print ' '.join(str(i) for i in list)

Or:

print ' '.join('{:.0f}'.format(i) for i in list)

Or:

print ' '.join('%i' % i for i in list)

As an aside, because list is a python builtin, it would be better practice to name your list something other than list so as not to overwrite it.

John1024
  • 109,961
  • 14
  • 137
  • 171
0
#!/bin/python
def insertionSort(list):

    for i in xrange(1,len(list)):
        value=list[i]
        pos=i
        while pos>0 and value <list[pos-1]:           
            list[pos]=list[pos-1]
            list_ = map(str, list)
            print " ".join(list_)
            pos-=1
        list[pos]=value
        list_ = map(str, list)
    return " ".join(list_)
m = input()
list = [int(i) for i in raw_input().strip().split()]
print insertionSort(list)

Thank you for your help but i did it this way

-2

You can try:

print str(list).replace("[","").replace(",","").replace("]","")

Regards

SorMun
  • 105
  • 4