Define a list range inside a list The 2019 Stack Overflow Developer Survey Results Are In ...
One-dimensional Japanese puzzle
Working through the single responsibility principle (SRP) in Python when calls are expensive
Could an empire control the whole planet with today's comunication methods?
Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?
how can a perfect fourth interval be considered either consonant or dissonant?
Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?
What was the last x86 CPU that did not have the x87 floating-point unit built in?
What aspect of planet Earth must be changed to prevent the industrial revolution?
Presidential Pardon
"is" operation returns false even though two objects have same id
Can each chord in a progression create its own key?
Huge performance difference of the command find with and without using %M option to show permissions
Is an up-to-date browser secure on an out-of-date OS?
Drawing vertical/oblique lines in Metrical tree (tikz-qtree, tipa)
How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time
Is 'stolen' appropriate word?
Didn't get enough time to take a Coding Test - what to do now?
Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?
Homework question about an engine pulling a train
Button changing its text & action. Good or terrible?
Accepted by European university, rejected by all American ones I applied to? Possible reasons?
Is there a writing software that you can sort scenes like slides in PowerPoint?
Are spiders unable to hurt humans, especially very small spiders?
How to determine omitted units in a publication
Define a list range inside a list
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceHow can I generate a list of consecutive numbers?How do I check if a list is empty?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow to return multiple values from a function?How to make a flat list out of list of lists“Least Astonishment” and the Mutable Default Argumentlist comprehension vs. lambda + filterHow do I list all files of a directory?Fastest way to check if a value exist in a listWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
in python is there a way to create of list that will skip numbers and will continue after skipping? something like the following code:
x = [1...3, 6...10]
print(x)
# [1,2,3,6,7,8,9,10]
Well its easy to write a for loop and then skip each defined index/value, or i can just use range, what I am looking for is a shorter more readable line. If not I can understand.
python
add a comment |
in python is there a way to create of list that will skip numbers and will continue after skipping? something like the following code:
x = [1...3, 6...10]
print(x)
# [1,2,3,6,7,8,9,10]
Well its easy to write a for loop and then skip each defined index/value, or i can just use range, what I am looking for is a shorter more readable line. If not I can understand.
python
Possible duplicate of How can I generate a list of consecutive numbers?
– ivan_pozdeev
9 hours ago
3
No @ivan_pozdeev, the suggested dupe does not consider multiple slice objects, rather a simple continuous range
– yatu
9 hours ago
1
Python doesn't support any special range syntax, never mind implicit concatenation of such within the same list literal.
– chepner
2 hours ago
add a comment |
in python is there a way to create of list that will skip numbers and will continue after skipping? something like the following code:
x = [1...3, 6...10]
print(x)
# [1,2,3,6,7,8,9,10]
Well its easy to write a for loop and then skip each defined index/value, or i can just use range, what I am looking for is a shorter more readable line. If not I can understand.
python
in python is there a way to create of list that will skip numbers and will continue after skipping? something like the following code:
x = [1...3, 6...10]
print(x)
# [1,2,3,6,7,8,9,10]
Well its easy to write a for loop and then skip each defined index/value, or i can just use range, what I am looking for is a shorter more readable line. If not I can understand.
python
python
edited 9 hours ago
Led
asked 9 hours ago
LedLed
424515
424515
Possible duplicate of How can I generate a list of consecutive numbers?
– ivan_pozdeev
9 hours ago
3
No @ivan_pozdeev, the suggested dupe does not consider multiple slice objects, rather a simple continuous range
– yatu
9 hours ago
1
Python doesn't support any special range syntax, never mind implicit concatenation of such within the same list literal.
– chepner
2 hours ago
add a comment |
Possible duplicate of How can I generate a list of consecutive numbers?
– ivan_pozdeev
9 hours ago
3
No @ivan_pozdeev, the suggested dupe does not consider multiple slice objects, rather a simple continuous range
– yatu
9 hours ago
1
Python doesn't support any special range syntax, never mind implicit concatenation of such within the same list literal.
– chepner
2 hours ago
Possible duplicate of How can I generate a list of consecutive numbers?
– ivan_pozdeev
9 hours ago
Possible duplicate of How can I generate a list of consecutive numbers?
– ivan_pozdeev
9 hours ago
3
3
No @ivan_pozdeev, the suggested dupe does not consider multiple slice objects, rather a simple continuous range
– yatu
9 hours ago
No @ivan_pozdeev, the suggested dupe does not consider multiple slice objects, rather a simple continuous range
– yatu
9 hours ago
1
1
Python doesn't support any special range syntax, never mind implicit concatenation of such within the same list literal.
– chepner
2 hours ago
Python doesn't support any special range syntax, never mind implicit concatenation of such within the same list literal.
– chepner
2 hours ago
add a comment |
4 Answers
4
active
oldest
votes
Simplest way to do this is to call range() and unpack result inside list assignment.
x = [*range(1, 4), *range(6, 11)]
Please name and refer to the docs of the corresponding syntax constructs
– ivan_pozdeev
9 hours ago
whats with the *?
– Led
9 hours ago
Exactly this is the way to go. gj
– Netwave
9 hours ago
2
@Led, Unpacking arguments
– Olvin Roght
9 hours ago
1
While this works, it's worth noting that this creates the entire list in memory. If you just want to iterate over the resulting sequence once, then this will consume more memory than theitertools.chainmethod. 40 bytes per number on my system, to be exact. This is fine for small sequences, but if your sequence has a billion numbers, well, you do the math...
– marcelm
6 hours ago
|
show 1 more comment
Alternatively you can use itertools.chain:
>>> import itertools
>>> list(itertools.chain(range(1, 5), range(20, 25)))
[1, 2, 3, 4, 20, 21, 22, 23, 24]
interesting, but is there no native way? i mean I need to import something? thank you very much
– Led
9 hours ago
4
@Led, itertools is one of the most powerful libs that come with python, it is as native as it can be. Otherwise the unpacking sintax is handy also.
– Netwave
9 hours ago
2
@Led why does it matter if you have to import from the standard library? It's part of Python
– juanpa.arrivillaga
9 hours ago
im looking for something short without importing.
– Led
9 hours ago
3
@Led Importing is your friend. Learn that sooner rather than later.
– wizzwizz4
6 hours ago
add a comment |
If numpy is an option, you can use np.r_ to concatenate slice objects:
import numpy as np
np.r_[range(1,4), range(6,11)]
# array([ 1, 2, 3, 6, 7, 8, 9, 10])
And since we just need slice objects you can writenp.r_[1:4, 6:11]as well.
– miradulo
2 hours ago
add a comment |
You can turn it into a recursive function:
def recursive_ranges(ranges):
if len(ranges) == 1:
return list(range(*ranges[0]))
else:
return list(range(*ranges[0])) + recursive_ranges(ranges[1:])
You can then call this, specifying ranges as a list of lists:
ranges = [[1, 4], [6, 11]]
recursive_ranges(ranges)
# [1, 2, 3, 6, 7, 8, 9, 10]
Note the *ranges[0] is used to unpack the elements in ranges[0] into individual arguments. Essentially the recursive function keeps grabbing the first element of ranges, each element of which is a two-element array, and passing those numbers into the range() method as two different values instead of one array. That's what the * does, it unpacks the array. First call, you unpack [1, 4] into range(1, 4) and then append the next call of the recursive function to it.
Basically this unpacks into the following:
list(range(1, 4)) + list(range(6, 11))
but you get to use a much more compact syntax, just passing a list of lists.
1
this will be too long for larger numbers
– Led
9 hours ago
1
@Led what do you mean? Also see my update with the recursive function. Pretty compact.
– Engineero
9 hours ago
thanks, but there is a need to write a function. Great idea by the way
– Led
9 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55654889%2fdefine-a-list-range-inside-a-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Simplest way to do this is to call range() and unpack result inside list assignment.
x = [*range(1, 4), *range(6, 11)]
Please name and refer to the docs of the corresponding syntax constructs
– ivan_pozdeev
9 hours ago
whats with the *?
– Led
9 hours ago
Exactly this is the way to go. gj
– Netwave
9 hours ago
2
@Led, Unpacking arguments
– Olvin Roght
9 hours ago
1
While this works, it's worth noting that this creates the entire list in memory. If you just want to iterate over the resulting sequence once, then this will consume more memory than theitertools.chainmethod. 40 bytes per number on my system, to be exact. This is fine for small sequences, but if your sequence has a billion numbers, well, you do the math...
– marcelm
6 hours ago
|
show 1 more comment
Simplest way to do this is to call range() and unpack result inside list assignment.
x = [*range(1, 4), *range(6, 11)]
Please name and refer to the docs of the corresponding syntax constructs
– ivan_pozdeev
9 hours ago
whats with the *?
– Led
9 hours ago
Exactly this is the way to go. gj
– Netwave
9 hours ago
2
@Led, Unpacking arguments
– Olvin Roght
9 hours ago
1
While this works, it's worth noting that this creates the entire list in memory. If you just want to iterate over the resulting sequence once, then this will consume more memory than theitertools.chainmethod. 40 bytes per number on my system, to be exact. This is fine for small sequences, but if your sequence has a billion numbers, well, you do the math...
– marcelm
6 hours ago
|
show 1 more comment
Simplest way to do this is to call range() and unpack result inside list assignment.
x = [*range(1, 4), *range(6, 11)]
Simplest way to do this is to call range() and unpack result inside list assignment.
x = [*range(1, 4), *range(6, 11)]
edited 9 hours ago
answered 9 hours ago
Olvin RoghtOlvin Roght
34219
34219
Please name and refer to the docs of the corresponding syntax constructs
– ivan_pozdeev
9 hours ago
whats with the *?
– Led
9 hours ago
Exactly this is the way to go. gj
– Netwave
9 hours ago
2
@Led, Unpacking arguments
– Olvin Roght
9 hours ago
1
While this works, it's worth noting that this creates the entire list in memory. If you just want to iterate over the resulting sequence once, then this will consume more memory than theitertools.chainmethod. 40 bytes per number on my system, to be exact. This is fine for small sequences, but if your sequence has a billion numbers, well, you do the math...
– marcelm
6 hours ago
|
show 1 more comment
Please name and refer to the docs of the corresponding syntax constructs
– ivan_pozdeev
9 hours ago
whats with the *?
– Led
9 hours ago
Exactly this is the way to go. gj
– Netwave
9 hours ago
2
@Led, Unpacking arguments
– Olvin Roght
9 hours ago
1
While this works, it's worth noting that this creates the entire list in memory. If you just want to iterate over the resulting sequence once, then this will consume more memory than theitertools.chainmethod. 40 bytes per number on my system, to be exact. This is fine for small sequences, but if your sequence has a billion numbers, well, you do the math...
– marcelm
6 hours ago
Please name and refer to the docs of the corresponding syntax constructs
– ivan_pozdeev
9 hours ago
Please name and refer to the docs of the corresponding syntax constructs
– ivan_pozdeev
9 hours ago
whats with the *?
– Led
9 hours ago
whats with the *?
– Led
9 hours ago
Exactly this is the way to go. gj
– Netwave
9 hours ago
Exactly this is the way to go. gj
– Netwave
9 hours ago
2
2
@Led, Unpacking arguments
– Olvin Roght
9 hours ago
@Led, Unpacking arguments
– Olvin Roght
9 hours ago
1
1
While this works, it's worth noting that this creates the entire list in memory. If you just want to iterate over the resulting sequence once, then this will consume more memory than the
itertools.chain method. 40 bytes per number on my system, to be exact. This is fine for small sequences, but if your sequence has a billion numbers, well, you do the math...– marcelm
6 hours ago
While this works, it's worth noting that this creates the entire list in memory. If you just want to iterate over the resulting sequence once, then this will consume more memory than the
itertools.chain method. 40 bytes per number on my system, to be exact. This is fine for small sequences, but if your sequence has a billion numbers, well, you do the math...– marcelm
6 hours ago
|
show 1 more comment
Alternatively you can use itertools.chain:
>>> import itertools
>>> list(itertools.chain(range(1, 5), range(20, 25)))
[1, 2, 3, 4, 20, 21, 22, 23, 24]
interesting, but is there no native way? i mean I need to import something? thank you very much
– Led
9 hours ago
4
@Led, itertools is one of the most powerful libs that come with python, it is as native as it can be. Otherwise the unpacking sintax is handy also.
– Netwave
9 hours ago
2
@Led why does it matter if you have to import from the standard library? It's part of Python
– juanpa.arrivillaga
9 hours ago
im looking for something short without importing.
– Led
9 hours ago
3
@Led Importing is your friend. Learn that sooner rather than later.
– wizzwizz4
6 hours ago
add a comment |
Alternatively you can use itertools.chain:
>>> import itertools
>>> list(itertools.chain(range(1, 5), range(20, 25)))
[1, 2, 3, 4, 20, 21, 22, 23, 24]
interesting, but is there no native way? i mean I need to import something? thank you very much
– Led
9 hours ago
4
@Led, itertools is one of the most powerful libs that come with python, it is as native as it can be. Otherwise the unpacking sintax is handy also.
– Netwave
9 hours ago
2
@Led why does it matter if you have to import from the standard library? It's part of Python
– juanpa.arrivillaga
9 hours ago
im looking for something short without importing.
– Led
9 hours ago
3
@Led Importing is your friend. Learn that sooner rather than later.
– wizzwizz4
6 hours ago
add a comment |
Alternatively you can use itertools.chain:
>>> import itertools
>>> list(itertools.chain(range(1, 5), range(20, 25)))
[1, 2, 3, 4, 20, 21, 22, 23, 24]
Alternatively you can use itertools.chain:
>>> import itertools
>>> list(itertools.chain(range(1, 5), range(20, 25)))
[1, 2, 3, 4, 20, 21, 22, 23, 24]
answered 9 hours ago
NetwaveNetwave
14.1k22247
14.1k22247
interesting, but is there no native way? i mean I need to import something? thank you very much
– Led
9 hours ago
4
@Led, itertools is one of the most powerful libs that come with python, it is as native as it can be. Otherwise the unpacking sintax is handy also.
– Netwave
9 hours ago
2
@Led why does it matter if you have to import from the standard library? It's part of Python
– juanpa.arrivillaga
9 hours ago
im looking for something short without importing.
– Led
9 hours ago
3
@Led Importing is your friend. Learn that sooner rather than later.
– wizzwizz4
6 hours ago
add a comment |
interesting, but is there no native way? i mean I need to import something? thank you very much
– Led
9 hours ago
4
@Led, itertools is one of the most powerful libs that come with python, it is as native as it can be. Otherwise the unpacking sintax is handy also.
– Netwave
9 hours ago
2
@Led why does it matter if you have to import from the standard library? It's part of Python
– juanpa.arrivillaga
9 hours ago
im looking for something short without importing.
– Led
9 hours ago
3
@Led Importing is your friend. Learn that sooner rather than later.
– wizzwizz4
6 hours ago
interesting, but is there no native way? i mean I need to import something? thank you very much
– Led
9 hours ago
interesting, but is there no native way? i mean I need to import something? thank you very much
– Led
9 hours ago
4
4
@Led, itertools is one of the most powerful libs that come with python, it is as native as it can be. Otherwise the unpacking sintax is handy also.
– Netwave
9 hours ago
@Led, itertools is one of the most powerful libs that come with python, it is as native as it can be. Otherwise the unpacking sintax is handy also.
– Netwave
9 hours ago
2
2
@Led why does it matter if you have to import from the standard library? It's part of Python
– juanpa.arrivillaga
9 hours ago
@Led why does it matter if you have to import from the standard library? It's part of Python
– juanpa.arrivillaga
9 hours ago
im looking for something short without importing.
– Led
9 hours ago
im looking for something short without importing.
– Led
9 hours ago
3
3
@Led Importing is your friend. Learn that sooner rather than later.
– wizzwizz4
6 hours ago
@Led Importing is your friend. Learn that sooner rather than later.
– wizzwizz4
6 hours ago
add a comment |
If numpy is an option, you can use np.r_ to concatenate slice objects:
import numpy as np
np.r_[range(1,4), range(6,11)]
# array([ 1, 2, 3, 6, 7, 8, 9, 10])
And since we just need slice objects you can writenp.r_[1:4, 6:11]as well.
– miradulo
2 hours ago
add a comment |
If numpy is an option, you can use np.r_ to concatenate slice objects:
import numpy as np
np.r_[range(1,4), range(6,11)]
# array([ 1, 2, 3, 6, 7, 8, 9, 10])
And since we just need slice objects you can writenp.r_[1:4, 6:11]as well.
– miradulo
2 hours ago
add a comment |
If numpy is an option, you can use np.r_ to concatenate slice objects:
import numpy as np
np.r_[range(1,4), range(6,11)]
# array([ 1, 2, 3, 6, 7, 8, 9, 10])
If numpy is an option, you can use np.r_ to concatenate slice objects:
import numpy as np
np.r_[range(1,4), range(6,11)]
# array([ 1, 2, 3, 6, 7, 8, 9, 10])
answered 9 hours ago
yatuyatu
15.8k41642
15.8k41642
And since we just need slice objects you can writenp.r_[1:4, 6:11]as well.
– miradulo
2 hours ago
add a comment |
And since we just need slice objects you can writenp.r_[1:4, 6:11]as well.
– miradulo
2 hours ago
And since we just need slice objects you can write
np.r_[1:4, 6:11] as well.– miradulo
2 hours ago
And since we just need slice objects you can write
np.r_[1:4, 6:11] as well.– miradulo
2 hours ago
add a comment |
You can turn it into a recursive function:
def recursive_ranges(ranges):
if len(ranges) == 1:
return list(range(*ranges[0]))
else:
return list(range(*ranges[0])) + recursive_ranges(ranges[1:])
You can then call this, specifying ranges as a list of lists:
ranges = [[1, 4], [6, 11]]
recursive_ranges(ranges)
# [1, 2, 3, 6, 7, 8, 9, 10]
Note the *ranges[0] is used to unpack the elements in ranges[0] into individual arguments. Essentially the recursive function keeps grabbing the first element of ranges, each element of which is a two-element array, and passing those numbers into the range() method as two different values instead of one array. That's what the * does, it unpacks the array. First call, you unpack [1, 4] into range(1, 4) and then append the next call of the recursive function to it.
Basically this unpacks into the following:
list(range(1, 4)) + list(range(6, 11))
but you get to use a much more compact syntax, just passing a list of lists.
1
this will be too long for larger numbers
– Led
9 hours ago
1
@Led what do you mean? Also see my update with the recursive function. Pretty compact.
– Engineero
9 hours ago
thanks, but there is a need to write a function. Great idea by the way
– Led
9 hours ago
add a comment |
You can turn it into a recursive function:
def recursive_ranges(ranges):
if len(ranges) == 1:
return list(range(*ranges[0]))
else:
return list(range(*ranges[0])) + recursive_ranges(ranges[1:])
You can then call this, specifying ranges as a list of lists:
ranges = [[1, 4], [6, 11]]
recursive_ranges(ranges)
# [1, 2, 3, 6, 7, 8, 9, 10]
Note the *ranges[0] is used to unpack the elements in ranges[0] into individual arguments. Essentially the recursive function keeps grabbing the first element of ranges, each element of which is a two-element array, and passing those numbers into the range() method as two different values instead of one array. That's what the * does, it unpacks the array. First call, you unpack [1, 4] into range(1, 4) and then append the next call of the recursive function to it.
Basically this unpacks into the following:
list(range(1, 4)) + list(range(6, 11))
but you get to use a much more compact syntax, just passing a list of lists.
1
this will be too long for larger numbers
– Led
9 hours ago
1
@Led what do you mean? Also see my update with the recursive function. Pretty compact.
– Engineero
9 hours ago
thanks, but there is a need to write a function. Great idea by the way
– Led
9 hours ago
add a comment |
You can turn it into a recursive function:
def recursive_ranges(ranges):
if len(ranges) == 1:
return list(range(*ranges[0]))
else:
return list(range(*ranges[0])) + recursive_ranges(ranges[1:])
You can then call this, specifying ranges as a list of lists:
ranges = [[1, 4], [6, 11]]
recursive_ranges(ranges)
# [1, 2, 3, 6, 7, 8, 9, 10]
Note the *ranges[0] is used to unpack the elements in ranges[0] into individual arguments. Essentially the recursive function keeps grabbing the first element of ranges, each element of which is a two-element array, and passing those numbers into the range() method as two different values instead of one array. That's what the * does, it unpacks the array. First call, you unpack [1, 4] into range(1, 4) and then append the next call of the recursive function to it.
Basically this unpacks into the following:
list(range(1, 4)) + list(range(6, 11))
but you get to use a much more compact syntax, just passing a list of lists.
You can turn it into a recursive function:
def recursive_ranges(ranges):
if len(ranges) == 1:
return list(range(*ranges[0]))
else:
return list(range(*ranges[0])) + recursive_ranges(ranges[1:])
You can then call this, specifying ranges as a list of lists:
ranges = [[1, 4], [6, 11]]
recursive_ranges(ranges)
# [1, 2, 3, 6, 7, 8, 9, 10]
Note the *ranges[0] is used to unpack the elements in ranges[0] into individual arguments. Essentially the recursive function keeps grabbing the first element of ranges, each element of which is a two-element array, and passing those numbers into the range() method as two different values instead of one array. That's what the * does, it unpacks the array. First call, you unpack [1, 4] into range(1, 4) and then append the next call of the recursive function to it.
Basically this unpacks into the following:
list(range(1, 4)) + list(range(6, 11))
but you get to use a much more compact syntax, just passing a list of lists.
edited 9 hours ago
answered 9 hours ago
EngineeroEngineero
6,48632351
6,48632351
1
this will be too long for larger numbers
– Led
9 hours ago
1
@Led what do you mean? Also see my update with the recursive function. Pretty compact.
– Engineero
9 hours ago
thanks, but there is a need to write a function. Great idea by the way
– Led
9 hours ago
add a comment |
1
this will be too long for larger numbers
– Led
9 hours ago
1
@Led what do you mean? Also see my update with the recursive function. Pretty compact.
– Engineero
9 hours ago
thanks, but there is a need to write a function. Great idea by the way
– Led
9 hours ago
1
1
this will be too long for larger numbers
– Led
9 hours ago
this will be too long for larger numbers
– Led
9 hours ago
1
1
@Led what do you mean? Also see my update with the recursive function. Pretty compact.
– Engineero
9 hours ago
@Led what do you mean? Also see my update with the recursive function. Pretty compact.
– Engineero
9 hours ago
thanks, but there is a need to write a function. Great idea by the way
– Led
9 hours ago
thanks, but there is a need to write a function. Great idea by the way
– Led
9 hours ago
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55654889%2fdefine-a-list-range-inside-a-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of How can I generate a list of consecutive numbers?
– ivan_pozdeev
9 hours ago
3
No @ivan_pozdeev, the suggested dupe does not consider multiple slice objects, rather a simple continuous range
– yatu
9 hours ago
1
Python doesn't support any special range syntax, never mind implicit concatenation of such within the same list literal.
– chepner
2 hours ago