Getting “None” instead of list of values in python [duplicate]
This question already has an answer here:
list.reverse does not return list?
8 answers
I am currently working on POC on Alibaba Cloud and not authorized to share the information. I am a beginner in python. Let me consider an example to address my issue.
I am getting none
instead of list of values,
Example code:
NumSet={1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet).reverse()
print(NumList)
Output:
None
What I am missing?
python python-3.x alibaba-cloud
marked as duplicate by juanpa.arrivillaga
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();
}
);
});
});
Dec 30 '18 at 14:42
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:
list.reverse does not return list?
8 answers
I am currently working on POC on Alibaba Cloud and not authorized to share the information. I am a beginner in python. Let me consider an example to address my issue.
I am getting none
instead of list of values,
Example code:
NumSet={1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet).reverse()
print(NumList)
Output:
None
What I am missing?
python python-3.x alibaba-cloud
marked as duplicate by juanpa.arrivillaga
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();
}
);
});
});
Dec 30 '18 at 14:42
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.
2
the.reverse()
method doesn't return anything, it directly change the list.
– iElden
Dec 30 '18 at 14:41
1
The most pythonic way to reverse a list isNumList[::-1]
. You don't need anyreverse
or other routines
– Bazingaa
Dec 30 '18 at 14:43
add a comment |
This question already has an answer here:
list.reverse does not return list?
8 answers
I am currently working on POC on Alibaba Cloud and not authorized to share the information. I am a beginner in python. Let me consider an example to address my issue.
I am getting none
instead of list of values,
Example code:
NumSet={1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet).reverse()
print(NumList)
Output:
None
What I am missing?
python python-3.x alibaba-cloud
This question already has an answer here:
list.reverse does not return list?
8 answers
I am currently working on POC on Alibaba Cloud and not authorized to share the information. I am a beginner in python. Let me consider an example to address my issue.
I am getting none
instead of list of values,
Example code:
NumSet={1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet).reverse()
print(NumList)
Output:
None
What I am missing?
This question already has an answer here:
list.reverse does not return list?
8 answers
python python-3.x alibaba-cloud
python python-3.x alibaba-cloud
asked Dec 30 '18 at 14:39
Ranjith UdayakumarRanjith Udayakumar
204
204
marked as duplicate by juanpa.arrivillaga
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();
}
);
});
});
Dec 30 '18 at 14:42
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 juanpa.arrivillaga
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();
}
);
});
});
Dec 30 '18 at 14:42
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.
2
the.reverse()
method doesn't return anything, it directly change the list.
– iElden
Dec 30 '18 at 14:41
1
The most pythonic way to reverse a list isNumList[::-1]
. You don't need anyreverse
or other routines
– Bazingaa
Dec 30 '18 at 14:43
add a comment |
2
the.reverse()
method doesn't return anything, it directly change the list.
– iElden
Dec 30 '18 at 14:41
1
The most pythonic way to reverse a list isNumList[::-1]
. You don't need anyreverse
or other routines
– Bazingaa
Dec 30 '18 at 14:43
2
2
the
.reverse()
method doesn't return anything, it directly change the list.– iElden
Dec 30 '18 at 14:41
the
.reverse()
method doesn't return anything, it directly change the list.– iElden
Dec 30 '18 at 14:41
1
1
The most pythonic way to reverse a list is
NumList[::-1]
. You don't need any reverse
or other routines– Bazingaa
Dec 30 '18 at 14:43
The most pythonic way to reverse a list is
NumList[::-1]
. You don't need any reverse
or other routines– Bazingaa
Dec 30 '18 at 14:43
add a comment |
2 Answers
2
active
oldest
votes
list.reverse()
reverses the list in-place and returns nothing (or returns None
).
NumList = list(NumSet) # convert to list first
NumList.reverse() # reverse in-place
This is the correct way to do it.
It should also be noted that if you need not-in-place reversal, you can iterate overreversed(list(NumSet))
.
– AKX
Dec 30 '18 at 14:43
@AKX What doesset()
in your code do?
– iBug
Dec 30 '18 at 14:43
Derp, I had misread the set-to-list conversion as being the other way around. Fixed.
– AKX
Dec 30 '18 at 14:46
add a comment |
list.reverse() doesn't return the list reversed. What it does is reversing the list in-place. Just change to this and it ill work
NumSet = {1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet)
NumList.reverse()
print(NumList)
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
list.reverse()
reverses the list in-place and returns nothing (or returns None
).
NumList = list(NumSet) # convert to list first
NumList.reverse() # reverse in-place
This is the correct way to do it.
It should also be noted that if you need not-in-place reversal, you can iterate overreversed(list(NumSet))
.
– AKX
Dec 30 '18 at 14:43
@AKX What doesset()
in your code do?
– iBug
Dec 30 '18 at 14:43
Derp, I had misread the set-to-list conversion as being the other way around. Fixed.
– AKX
Dec 30 '18 at 14:46
add a comment |
list.reverse()
reverses the list in-place and returns nothing (or returns None
).
NumList = list(NumSet) # convert to list first
NumList.reverse() # reverse in-place
This is the correct way to do it.
It should also be noted that if you need not-in-place reversal, you can iterate overreversed(list(NumSet))
.
– AKX
Dec 30 '18 at 14:43
@AKX What doesset()
in your code do?
– iBug
Dec 30 '18 at 14:43
Derp, I had misread the set-to-list conversion as being the other way around. Fixed.
– AKX
Dec 30 '18 at 14:46
add a comment |
list.reverse()
reverses the list in-place and returns nothing (or returns None
).
NumList = list(NumSet) # convert to list first
NumList.reverse() # reverse in-place
This is the correct way to do it.
list.reverse()
reverses the list in-place and returns nothing (or returns None
).
NumList = list(NumSet) # convert to list first
NumList.reverse() # reverse in-place
This is the correct way to do it.
answered Dec 30 '18 at 14:41
iBugiBug
20.4k63864
20.4k63864
It should also be noted that if you need not-in-place reversal, you can iterate overreversed(list(NumSet))
.
– AKX
Dec 30 '18 at 14:43
@AKX What doesset()
in your code do?
– iBug
Dec 30 '18 at 14:43
Derp, I had misread the set-to-list conversion as being the other way around. Fixed.
– AKX
Dec 30 '18 at 14:46
add a comment |
It should also be noted that if you need not-in-place reversal, you can iterate overreversed(list(NumSet))
.
– AKX
Dec 30 '18 at 14:43
@AKX What doesset()
in your code do?
– iBug
Dec 30 '18 at 14:43
Derp, I had misread the set-to-list conversion as being the other way around. Fixed.
– AKX
Dec 30 '18 at 14:46
It should also be noted that if you need not-in-place reversal, you can iterate over
reversed(list(NumSet))
.– AKX
Dec 30 '18 at 14:43
It should also be noted that if you need not-in-place reversal, you can iterate over
reversed(list(NumSet))
.– AKX
Dec 30 '18 at 14:43
@AKX What does
set()
in your code do?– iBug
Dec 30 '18 at 14:43
@AKX What does
set()
in your code do?– iBug
Dec 30 '18 at 14:43
Derp, I had misread the set-to-list conversion as being the other way around. Fixed.
– AKX
Dec 30 '18 at 14:46
Derp, I had misread the set-to-list conversion as being the other way around. Fixed.
– AKX
Dec 30 '18 at 14:46
add a comment |
list.reverse() doesn't return the list reversed. What it does is reversing the list in-place. Just change to this and it ill work
NumSet = {1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet)
NumList.reverse()
print(NumList)
add a comment |
list.reverse() doesn't return the list reversed. What it does is reversing the list in-place. Just change to this and it ill work
NumSet = {1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet)
NumList.reverse()
print(NumList)
add a comment |
list.reverse() doesn't return the list reversed. What it does is reversing the list in-place. Just change to this and it ill work
NumSet = {1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet)
NumList.reverse()
print(NumList)
list.reverse() doesn't return the list reversed. What it does is reversing the list in-place. Just change to this and it ill work
NumSet = {1,2,3,4,5,6,7,8,9,10}
NumList = list(NumSet)
NumList.reverse()
print(NumList)
answered Dec 30 '18 at 14:46
BiriveraBirivera
75
75
add a comment |
add a comment |
2
the
.reverse()
method doesn't return anything, it directly change the list.– iElden
Dec 30 '18 at 14:41
1
The most pythonic way to reverse a list is
NumList[::-1]
. You don't need anyreverse
or other routines– Bazingaa
Dec 30 '18 at 14:43