Gnome Sort not sorting in python? [duplicate]
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.
python
marked as duplicate by tripleee, Prune
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.
add a comment |
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.
python
marked as duplicate by tripleee, Prune
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, henceNone
, tryreturn 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 onlis
and then printlis
.
– 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
add a comment |
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.
python
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
python
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
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
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, henceNone
, tryreturn 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 onlis
and then printlis
.
– 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
add a comment |
1
your return statement is not returning anything, henceNone
, tryreturn 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 onlis
and then printlis
.
– 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
add a comment |
1 Answer
1
active
oldest
votes
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)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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)
add a comment |
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)
add a comment |
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)
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)
answered Nov 12 '18 at 17:02
PrunePrune
43.2k143456
43.2k143456
add a comment |
add a comment |
1
your return statement is not returning anything, hence
None
, tryreturn 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 printlis
.– 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