Gnome Sort not sorting in python? [duplicate]










-1
















This question already has an answer here:



  • Python Script returns unintended “None” after execution of a function

    1 answer



When I try to run my code it returns with none.



def gnomeSort(lis):
i = 0
n = len(lis)
while i < n:
if i and lis[i] < lis[i-1]:
lis[i], lis[i-1] = lis[i-1], lis[i]
i -= 1
else:
i += 1
return


lis = [1,3,5,20,19,30,2,6,19,23,31,90,44,62,69,21,78,89,64]
print(gnomeSort(lis))


When I run this it returns with "None", even though I provided a list to be sorted.










share|improve this question















marked as duplicate by tripleee, Prune python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 17:02


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    your return statement is not returning anything, hence None, try return lis

    – Netwave
    Nov 12 '18 at 17:00






  • 1





    You need to put something after your return statement, as currently it is not returning anything

    – D Manokhin
    Nov 12 '18 at 17:01






  • 1





    This implementation sorts in-place, meaning you just call it on lis and then print lis.

    – L3viathan
    Nov 12 '18 at 17:01











  • Did you try this simple command to sort your list. print sorted(lis)

    – mGm
    Nov 12 '18 at 17:04
















-1
















This question already has an answer here:



  • Python Script returns unintended “None” after execution of a function

    1 answer



When I try to run my code it returns with none.



def gnomeSort(lis):
i = 0
n = len(lis)
while i < n:
if i and lis[i] < lis[i-1]:
lis[i], lis[i-1] = lis[i-1], lis[i]
i -= 1
else:
i += 1
return


lis = [1,3,5,20,19,30,2,6,19,23,31,90,44,62,69,21,78,89,64]
print(gnomeSort(lis))


When I run this it returns with "None", even though I provided a list to be sorted.










share|improve this question















marked as duplicate by tripleee, Prune python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 17:02


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    your return statement is not returning anything, hence None, try return lis

    – Netwave
    Nov 12 '18 at 17:00






  • 1





    You need to put something after your return statement, as currently it is not returning anything

    – D Manokhin
    Nov 12 '18 at 17:01






  • 1





    This implementation sorts in-place, meaning you just call it on lis and then print lis.

    – L3viathan
    Nov 12 '18 at 17:01











  • Did you try this simple command to sort your list. print sorted(lis)

    – mGm
    Nov 12 '18 at 17:04














-1












-1








-1









This question already has an answer here:



  • Python Script returns unintended “None” after execution of a function

    1 answer



When I try to run my code it returns with none.



def gnomeSort(lis):
i = 0
n = len(lis)
while i < n:
if i and lis[i] < lis[i-1]:
lis[i], lis[i-1] = lis[i-1], lis[i]
i -= 1
else:
i += 1
return


lis = [1,3,5,20,19,30,2,6,19,23,31,90,44,62,69,21,78,89,64]
print(gnomeSort(lis))


When I run this it returns with "None", even though I provided a list to be sorted.










share|improve this question

















This question already has an answer here:



  • Python Script returns unintended “None” after execution of a function

    1 answer



When I try to run my code it returns with none.



def gnomeSort(lis):
i = 0
n = len(lis)
while i < n:
if i and lis[i] < lis[i-1]:
lis[i], lis[i-1] = lis[i-1], lis[i]
i -= 1
else:
i += 1
return


lis = [1,3,5,20,19,30,2,6,19,23,31,90,44,62,69,21,78,89,64]
print(gnomeSort(lis))


When I run this it returns with "None", even though I provided a list to be sorted.





This question already has an answer here:



  • Python Script returns unintended “None” after execution of a function

    1 answer







python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 17:00









Prune

43.2k143456




43.2k143456










asked Nov 12 '18 at 16:58









Noah SantosNoah Santos

417




417




marked as duplicate by tripleee, Prune python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 17:02


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by tripleee, Prune python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 '18 at 17:02


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 1





    your return statement is not returning anything, hence None, try return lis

    – Netwave
    Nov 12 '18 at 17:00






  • 1





    You need to put something after your return statement, as currently it is not returning anything

    – D Manokhin
    Nov 12 '18 at 17:01






  • 1





    This implementation sorts in-place, meaning you just call it on lis and then print lis.

    – L3viathan
    Nov 12 '18 at 17:01











  • Did you try this simple command to sort your list. print sorted(lis)

    – mGm
    Nov 12 '18 at 17:04













  • 1





    your return statement is not returning anything, hence None, try return lis

    – Netwave
    Nov 12 '18 at 17:00






  • 1





    You need to put something after your return statement, as currently it is not returning anything

    – D Manokhin
    Nov 12 '18 at 17:01






  • 1





    This implementation sorts in-place, meaning you just call it on lis and then print lis.

    – L3viathan
    Nov 12 '18 at 17:01











  • Did you try this simple command to sort your list. print sorted(lis)

    – mGm
    Nov 12 '18 at 17:04








1




1





your return statement is not returning anything, hence None, try return lis

– Netwave
Nov 12 '18 at 17:00





your return statement is not returning anything, hence None, try return lis

– Netwave
Nov 12 '18 at 17:00




1




1





You need to put something after your return statement, as currently it is not returning anything

– D Manokhin
Nov 12 '18 at 17:01





You need to put something after your return statement, as currently it is not returning anything

– D Manokhin
Nov 12 '18 at 17:01




1




1





This implementation sorts in-place, meaning you just call it on lis and then print lis.

– L3viathan
Nov 12 '18 at 17:01





This implementation sorts in-place, meaning you just call it on lis and then print lis.

– L3viathan
Nov 12 '18 at 17:01













Did you try this simple command to sort your list. print sorted(lis)

– mGm
Nov 12 '18 at 17:04






Did you try this simple command to sort your list. print sorted(lis)

– mGm
Nov 12 '18 at 17:04













1 Answer
1






active

oldest

votes


















3














Your wrote your function much like the built-in sort functions: it sorts the list in place and returns None. Print the sorted list, not the return value.



print(lis)





share|improve this answer





























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Your wrote your function much like the built-in sort functions: it sorts the list in place and returns None. Print the sorted list, not the return value.



    print(lis)





    share|improve this answer



























      3














      Your wrote your function much like the built-in sort functions: it sorts the list in place and returns None. Print the sorted list, not the return value.



      print(lis)





      share|improve this answer

























        3












        3








        3







        Your wrote your function much like the built-in sort functions: it sorts the list in place and returns None. Print the sorted list, not the return value.



        print(lis)





        share|improve this answer













        Your wrote your function much like the built-in sort functions: it sorts the list in place and returns None. Print the sorted list, not the return value.



        print(lis)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 '18 at 17:02









        PrunePrune

        43.2k143456




        43.2k143456













            Popular posts from this blog

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Syphilis

            Darth Vader #20