Concatenation of the result of a function with a mutable default argument in pythonCalling a function of a module by using its name (a string)“Least Astonishment” and the Mutable Default ArgumentHow do I concatenate two lists in Python?Good uses for mutable function argument default values?Instantiation time for mutable default arguments of closures in PythonWarning about mutable default argument in PyCharmFunctions with mutable default values
Church Booleans
Concatenation of the result of a function with a mutable default argument in python
Sleeping solo in a double sleeping bag
Check in to 2 hotels at same location
If all stars rotate, why was there a theory developed, that requires non-rotating stars?
Three Singles in Three Clubs
Was Switzerland really impossible to invade during WW2?
Fried gnocchi with spinach, bacon, cream sauce in a single pan
Defense against attacks using dictionaries
Why did this happen to Thanos's ships at the end of "Avengers: Endgame"?
The teacher logged me in as administrator for doing a short task, is the whole system now compromised?
LeetCode: Pascal's Triangle C#
Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?
Why is my Earth simulation slower than the reality?
How do I make distance between concentric circles equal?
Why doesn't the Falcon-9 first stage use three legs to land?
Avoiding racist tropes in fantasy
How do I find the fastest route from Heathrow to an address in London using all forms of transport?
If the first law of thermodynamics ensures conservation of energy, why does it allow systems to lose energy?
IndexOptimize - Configuration
Why does The Ancient One think differently about Doctor Strange in Endgame than the film Doctor Strange?
What professions would a medieval village with a population of 100 need?
Why is observed clock rate < 3MHz on Arduino Uno?
Is refusing to concede in the face of an unstoppable Nexus combo punishable?
Concatenation of the result of a function with a mutable default argument in python
Calling a function of a module by using its name (a string)“Least Astonishment” and the Mutable Default ArgumentHow do I concatenate two lists in Python?Good uses for mutable function argument default values?Instantiation time for mutable default arguments of closures in PythonWarning about mutable default argument in PyCharmFunctions with mutable default values
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Suppose a function with a mutable default argument:
def f(l=[]):
l.append(len(l))
return l
If I run this:
def f(l=[]):
l.append(len(l))
return l
print(f()+["-"]+f()+["-"]+f()) # -> [0, '-', 0, 1, '-', 0, 1, 2]
If I run this:
def f(l=[]):
l.append(len(l))
return l
print(f()+f()+f()) # -> [0, 1, 0, 1, 0, 1, 2]
Instead of this, which would be more logical:
print(f()+f()+f()) # -> [0, 0, 1, 0, 1, 2]
Why ?
python python-3.x
add a comment |
Suppose a function with a mutable default argument:
def f(l=[]):
l.append(len(l))
return l
If I run this:
def f(l=[]):
l.append(len(l))
return l
print(f()+["-"]+f()+["-"]+f()) # -> [0, '-', 0, 1, '-', 0, 1, 2]
If I run this:
def f(l=[]):
l.append(len(l))
return l
print(f()+f()+f()) # -> [0, 1, 0, 1, 0, 1, 2]
Instead of this, which would be more logical:
print(f()+f()+f()) # -> [0, 0, 1, 0, 1, 2]
Why ?
python python-3.x
if you want to see the result of individual functional call then usereturn [l.copy()]
– prashant rana
8 hours ago
Well the last funciont returns me this:[0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5]
– Celius Stingher
8 hours ago
@CeliusStingher You have to redefine the function between uses.
– Benoît Pilatte
8 hours ago
with-you will be able to distinguish between your data from each functional call , in second one you need to write a code to get the pattern
– prashant rana
8 hours ago
add a comment |
Suppose a function with a mutable default argument:
def f(l=[]):
l.append(len(l))
return l
If I run this:
def f(l=[]):
l.append(len(l))
return l
print(f()+["-"]+f()+["-"]+f()) # -> [0, '-', 0, 1, '-', 0, 1, 2]
If I run this:
def f(l=[]):
l.append(len(l))
return l
print(f()+f()+f()) # -> [0, 1, 0, 1, 0, 1, 2]
Instead of this, which would be more logical:
print(f()+f()+f()) # -> [0, 0, 1, 0, 1, 2]
Why ?
python python-3.x
Suppose a function with a mutable default argument:
def f(l=[]):
l.append(len(l))
return l
If I run this:
def f(l=[]):
l.append(len(l))
return l
print(f()+["-"]+f()+["-"]+f()) # -> [0, '-', 0, 1, '-', 0, 1, 2]
If I run this:
def f(l=[]):
l.append(len(l))
return l
print(f()+f()+f()) # -> [0, 1, 0, 1, 0, 1, 2]
Instead of this, which would be more logical:
print(f()+f()+f()) # -> [0, 0, 1, 0, 1, 2]
Why ?
python python-3.x
python python-3.x
edited 8 hours ago
Benoît Pilatte
asked 8 hours ago
Benoît PilatteBenoît Pilatte
1,6274 silver badges23 bronze badges
1,6274 silver badges23 bronze badges
if you want to see the result of individual functional call then usereturn [l.copy()]
– prashant rana
8 hours ago
Well the last funciont returns me this:[0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5]
– Celius Stingher
8 hours ago
@CeliusStingher You have to redefine the function between uses.
– Benoît Pilatte
8 hours ago
with-you will be able to distinguish between your data from each functional call , in second one you need to write a code to get the pattern
– prashant rana
8 hours ago
add a comment |
if you want to see the result of individual functional call then usereturn [l.copy()]
– prashant rana
8 hours ago
Well the last funciont returns me this:[0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5]
– Celius Stingher
8 hours ago
@CeliusStingher You have to redefine the function between uses.
– Benoît Pilatte
8 hours ago
with-you will be able to distinguish between your data from each functional call , in second one you need to write a code to get the pattern
– prashant rana
8 hours ago
if you want to see the result of individual functional call then use
return [l.copy()]– prashant rana
8 hours ago
if you want to see the result of individual functional call then use
return [l.copy()]– prashant rana
8 hours ago
Well the last funciont returns me this:
[0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5]– Celius Stingher
8 hours ago
Well the last funciont returns me this:
[0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5]– Celius Stingher
8 hours ago
@CeliusStingher You have to redefine the function between uses.
– Benoît Pilatte
8 hours ago
@CeliusStingher You have to redefine the function between uses.
– Benoît Pilatte
8 hours ago
with
- you will be able to distinguish between your data from each functional call , in second one you need to write a code to get the pattern– prashant rana
8 hours ago
with
- you will be able to distinguish between your data from each functional call , in second one you need to write a code to get the pattern– prashant rana
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
That's actually pretty interesting!
As we know, the list l in the function definition is initialized only once at the definition of this function, and for all invocations of this function, there will be exactly one copy of this list. Now, the function modifies this list, which means that multiple calls to this function will modify the exact same object multiple times. This is the first important part.
Now, consider the expression that adds these lists:
f()+f()+f()
According to the laws of operator precedence, this is equivalent to the following:
(f() + f()) + f()
...which is exactly the same as this:
temp1 = f() + f() # (1)
temp2 = temp1 + f() # (2)
This is the second important part.
Addition of lists produces a new object, without modifying any of its arguments. This is the third important part.
Now let's combine what we know together.
In line 1 above, the first call returns [0], as you'd expect. The second call returns [0, 1], as you'd expect. Oh, wait! The function will return the exact same object (not its copy!) over and over again, after modifying it! This means that the object that the first call returned has now changed to become [0, 1] as well! And that's why temp1 == [0, 1] + [0, 1].
The result of addition, however, is a completely new object, so [0, 1, 0, 1] + f() is the same as [0, 1, 0, 1] + [0, 1, 2]. Note that the second list is, again, exactly what you'd expect your function to return. The same thing happens when you add f() + ["-"]: this creates a new list object, so that any other calls to f won't interfere with it.
You can reproduce this by concatenating the results of two function calls:
>>> f() + f()
[0, 1, 0, 1]
>>> f() + f()
[0, 1, 2, 3, 0, 1, 2, 3]
>>> f() + f()
[0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5]
Again, you can do all that because you're concatenating references to the same object.
Wow, 🤯. The best thing about this answer is that it is right.[]+f()+f()gives[0, 0, 1]andf()+f()+[]gives[0, 1, 0, 1]!!!
– Benoît Pilatte
8 hours ago
2
The new object returned by+is definitely the key here, it's so subtle
– C.Nivs
8 hours ago
1
A good reminder for why a mutable default argument is a big no-no.
– EliadL
8 hours ago
2
Looked intodis(lambda: f()+f()+f())and the functionfdid get called twice beforeaddis performed. Great answer btw.
– Henry Yik
7 hours ago
1
@HenryYik it's because of howlist.__add__is implemented. The firstf()instantiates the list object, let's call itl1. Thenl1.__add__(f())is called, so,f()needs to be evaluated first, which changes the reference that is shared withl1. Thenl1.__add__(l2)finishes, returning the new object.
– C.Nivs
7 hours ago
|
show 3 more comments
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%2f57593294%2fconcatenation-of-the-result-of-a-function-with-a-mutable-default-argument-in-pyt%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
That's actually pretty interesting!
As we know, the list l in the function definition is initialized only once at the definition of this function, and for all invocations of this function, there will be exactly one copy of this list. Now, the function modifies this list, which means that multiple calls to this function will modify the exact same object multiple times. This is the first important part.
Now, consider the expression that adds these lists:
f()+f()+f()
According to the laws of operator precedence, this is equivalent to the following:
(f() + f()) + f()
...which is exactly the same as this:
temp1 = f() + f() # (1)
temp2 = temp1 + f() # (2)
This is the second important part.
Addition of lists produces a new object, without modifying any of its arguments. This is the third important part.
Now let's combine what we know together.
In line 1 above, the first call returns [0], as you'd expect. The second call returns [0, 1], as you'd expect. Oh, wait! The function will return the exact same object (not its copy!) over and over again, after modifying it! This means that the object that the first call returned has now changed to become [0, 1] as well! And that's why temp1 == [0, 1] + [0, 1].
The result of addition, however, is a completely new object, so [0, 1, 0, 1] + f() is the same as [0, 1, 0, 1] + [0, 1, 2]. Note that the second list is, again, exactly what you'd expect your function to return. The same thing happens when you add f() + ["-"]: this creates a new list object, so that any other calls to f won't interfere with it.
You can reproduce this by concatenating the results of two function calls:
>>> f() + f()
[0, 1, 0, 1]
>>> f() + f()
[0, 1, 2, 3, 0, 1, 2, 3]
>>> f() + f()
[0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5]
Again, you can do all that because you're concatenating references to the same object.
Wow, 🤯. The best thing about this answer is that it is right.[]+f()+f()gives[0, 0, 1]andf()+f()+[]gives[0, 1, 0, 1]!!!
– Benoît Pilatte
8 hours ago
2
The new object returned by+is definitely the key here, it's so subtle
– C.Nivs
8 hours ago
1
A good reminder for why a mutable default argument is a big no-no.
– EliadL
8 hours ago
2
Looked intodis(lambda: f()+f()+f())and the functionfdid get called twice beforeaddis performed. Great answer btw.
– Henry Yik
7 hours ago
1
@HenryYik it's because of howlist.__add__is implemented. The firstf()instantiates the list object, let's call itl1. Thenl1.__add__(f())is called, so,f()needs to be evaluated first, which changes the reference that is shared withl1. Thenl1.__add__(l2)finishes, returning the new object.
– C.Nivs
7 hours ago
|
show 3 more comments
That's actually pretty interesting!
As we know, the list l in the function definition is initialized only once at the definition of this function, and for all invocations of this function, there will be exactly one copy of this list. Now, the function modifies this list, which means that multiple calls to this function will modify the exact same object multiple times. This is the first important part.
Now, consider the expression that adds these lists:
f()+f()+f()
According to the laws of operator precedence, this is equivalent to the following:
(f() + f()) + f()
...which is exactly the same as this:
temp1 = f() + f() # (1)
temp2 = temp1 + f() # (2)
This is the second important part.
Addition of lists produces a new object, without modifying any of its arguments. This is the third important part.
Now let's combine what we know together.
In line 1 above, the first call returns [0], as you'd expect. The second call returns [0, 1], as you'd expect. Oh, wait! The function will return the exact same object (not its copy!) over and over again, after modifying it! This means that the object that the first call returned has now changed to become [0, 1] as well! And that's why temp1 == [0, 1] + [0, 1].
The result of addition, however, is a completely new object, so [0, 1, 0, 1] + f() is the same as [0, 1, 0, 1] + [0, 1, 2]. Note that the second list is, again, exactly what you'd expect your function to return. The same thing happens when you add f() + ["-"]: this creates a new list object, so that any other calls to f won't interfere with it.
You can reproduce this by concatenating the results of two function calls:
>>> f() + f()
[0, 1, 0, 1]
>>> f() + f()
[0, 1, 2, 3, 0, 1, 2, 3]
>>> f() + f()
[0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5]
Again, you can do all that because you're concatenating references to the same object.
Wow, 🤯. The best thing about this answer is that it is right.[]+f()+f()gives[0, 0, 1]andf()+f()+[]gives[0, 1, 0, 1]!!!
– Benoît Pilatte
8 hours ago
2
The new object returned by+is definitely the key here, it's so subtle
– C.Nivs
8 hours ago
1
A good reminder for why a mutable default argument is a big no-no.
– EliadL
8 hours ago
2
Looked intodis(lambda: f()+f()+f())and the functionfdid get called twice beforeaddis performed. Great answer btw.
– Henry Yik
7 hours ago
1
@HenryYik it's because of howlist.__add__is implemented. The firstf()instantiates the list object, let's call itl1. Thenl1.__add__(f())is called, so,f()needs to be evaluated first, which changes the reference that is shared withl1. Thenl1.__add__(l2)finishes, returning the new object.
– C.Nivs
7 hours ago
|
show 3 more comments
That's actually pretty interesting!
As we know, the list l in the function definition is initialized only once at the definition of this function, and for all invocations of this function, there will be exactly one copy of this list. Now, the function modifies this list, which means that multiple calls to this function will modify the exact same object multiple times. This is the first important part.
Now, consider the expression that adds these lists:
f()+f()+f()
According to the laws of operator precedence, this is equivalent to the following:
(f() + f()) + f()
...which is exactly the same as this:
temp1 = f() + f() # (1)
temp2 = temp1 + f() # (2)
This is the second important part.
Addition of lists produces a new object, without modifying any of its arguments. This is the third important part.
Now let's combine what we know together.
In line 1 above, the first call returns [0], as you'd expect. The second call returns [0, 1], as you'd expect. Oh, wait! The function will return the exact same object (not its copy!) over and over again, after modifying it! This means that the object that the first call returned has now changed to become [0, 1] as well! And that's why temp1 == [0, 1] + [0, 1].
The result of addition, however, is a completely new object, so [0, 1, 0, 1] + f() is the same as [0, 1, 0, 1] + [0, 1, 2]. Note that the second list is, again, exactly what you'd expect your function to return. The same thing happens when you add f() + ["-"]: this creates a new list object, so that any other calls to f won't interfere with it.
You can reproduce this by concatenating the results of two function calls:
>>> f() + f()
[0, 1, 0, 1]
>>> f() + f()
[0, 1, 2, 3, 0, 1, 2, 3]
>>> f() + f()
[0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5]
Again, you can do all that because you're concatenating references to the same object.
That's actually pretty interesting!
As we know, the list l in the function definition is initialized only once at the definition of this function, and for all invocations of this function, there will be exactly one copy of this list. Now, the function modifies this list, which means that multiple calls to this function will modify the exact same object multiple times. This is the first important part.
Now, consider the expression that adds these lists:
f()+f()+f()
According to the laws of operator precedence, this is equivalent to the following:
(f() + f()) + f()
...which is exactly the same as this:
temp1 = f() + f() # (1)
temp2 = temp1 + f() # (2)
This is the second important part.
Addition of lists produces a new object, without modifying any of its arguments. This is the third important part.
Now let's combine what we know together.
In line 1 above, the first call returns [0], as you'd expect. The second call returns [0, 1], as you'd expect. Oh, wait! The function will return the exact same object (not its copy!) over and over again, after modifying it! This means that the object that the first call returned has now changed to become [0, 1] as well! And that's why temp1 == [0, 1] + [0, 1].
The result of addition, however, is a completely new object, so [0, 1, 0, 1] + f() is the same as [0, 1, 0, 1] + [0, 1, 2]. Note that the second list is, again, exactly what you'd expect your function to return. The same thing happens when you add f() + ["-"]: this creates a new list object, so that any other calls to f won't interfere with it.
You can reproduce this by concatenating the results of two function calls:
>>> f() + f()
[0, 1, 0, 1]
>>> f() + f()
[0, 1, 2, 3, 0, 1, 2, 3]
>>> f() + f()
[0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5]
Again, you can do all that because you're concatenating references to the same object.
edited 4 hours ago
answered 8 hours ago
ForceBruForceBru
24.6k9 gold badges36 silver badges62 bronze badges
24.6k9 gold badges36 silver badges62 bronze badges
Wow, 🤯. The best thing about this answer is that it is right.[]+f()+f()gives[0, 0, 1]andf()+f()+[]gives[0, 1, 0, 1]!!!
– Benoît Pilatte
8 hours ago
2
The new object returned by+is definitely the key here, it's so subtle
– C.Nivs
8 hours ago
1
A good reminder for why a mutable default argument is a big no-no.
– EliadL
8 hours ago
2
Looked intodis(lambda: f()+f()+f())and the functionfdid get called twice beforeaddis performed. Great answer btw.
– Henry Yik
7 hours ago
1
@HenryYik it's because of howlist.__add__is implemented. The firstf()instantiates the list object, let's call itl1. Thenl1.__add__(f())is called, so,f()needs to be evaluated first, which changes the reference that is shared withl1. Thenl1.__add__(l2)finishes, returning the new object.
– C.Nivs
7 hours ago
|
show 3 more comments
Wow, 🤯. The best thing about this answer is that it is right.[]+f()+f()gives[0, 0, 1]andf()+f()+[]gives[0, 1, 0, 1]!!!
– Benoît Pilatte
8 hours ago
2
The new object returned by+is definitely the key here, it's so subtle
– C.Nivs
8 hours ago
1
A good reminder for why a mutable default argument is a big no-no.
– EliadL
8 hours ago
2
Looked intodis(lambda: f()+f()+f())and the functionfdid get called twice beforeaddis performed. Great answer btw.
– Henry Yik
7 hours ago
1
@HenryYik it's because of howlist.__add__is implemented. The firstf()instantiates the list object, let's call itl1. Thenl1.__add__(f())is called, so,f()needs to be evaluated first, which changes the reference that is shared withl1. Thenl1.__add__(l2)finishes, returning the new object.
– C.Nivs
7 hours ago
Wow, 🤯. The best thing about this answer is that it is right.
[]+f()+f() gives [0, 0, 1] and f()+f()+[] gives [0, 1, 0, 1] !!!– Benoît Pilatte
8 hours ago
Wow, 🤯. The best thing about this answer is that it is right.
[]+f()+f() gives [0, 0, 1] and f()+f()+[] gives [0, 1, 0, 1] !!!– Benoît Pilatte
8 hours ago
2
2
The new object returned by
+ is definitely the key here, it's so subtle– C.Nivs
8 hours ago
The new object returned by
+ is definitely the key here, it's so subtle– C.Nivs
8 hours ago
1
1
A good reminder for why a mutable default argument is a big no-no.
– EliadL
8 hours ago
A good reminder for why a mutable default argument is a big no-no.
– EliadL
8 hours ago
2
2
Looked into
dis(lambda: f()+f()+f()) and the function f did get called twice before add is performed. Great answer btw.– Henry Yik
7 hours ago
Looked into
dis(lambda: f()+f()+f()) and the function f did get called twice before add is performed. Great answer btw.– Henry Yik
7 hours ago
1
1
@HenryYik it's because of how
list.__add__ is implemented. The first f() instantiates the list object, let's call it l1. Then l1.__add__(f()) is called, so, f() needs to be evaluated first, which changes the reference that is shared with l1. Then l1.__add__(l2) finishes, returning the new object.– C.Nivs
7 hours ago
@HenryYik it's because of how
list.__add__ is implemented. The first f() instantiates the list object, let's call it l1. Then l1.__add__(f()) is called, so, f() needs to be evaluated first, which changes the reference that is shared with l1. Then l1.__add__(l2) finishes, returning the new object.– C.Nivs
7 hours ago
|
show 3 more comments
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f57593294%2fconcatenation-of-the-result-of-a-function-with-a-mutable-default-argument-in-pyt%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
if you want to see the result of individual functional call then use
return [l.copy()]– prashant rana
8 hours ago
Well the last funciont returns me this:
[0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5]– Celius Stingher
8 hours ago
@CeliusStingher You have to redefine the function between uses.
– Benoît Pilatte
8 hours ago
with
-you will be able to distinguish between your data from each functional call , in second one you need to write a code to get the pattern– prashant rana
8 hours ago