Fastest way to merge two deques
up vote
2
down vote
favorite
Exist a faster way to merge two deques than this?
# a, b are two deques. The maximum length
# of a is greater than the current length
# of a plus the current length of b
while len(b):
a.append(b.popleft())
Note that I'm not interested in preserving input deques, I'm only interested in having the merged one as fast as possible.
python merge deque
add a comment |
up vote
2
down vote
favorite
Exist a faster way to merge two deques than this?
# a, b are two deques. The maximum length
# of a is greater than the current length
# of a plus the current length of b
while len(b):
a.append(b.popleft())
Note that I'm not interested in preserving input deques, I'm only interested in having the merged one as fast as possible.
python merge deque
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Exist a faster way to merge two deques than this?
# a, b are two deques. The maximum length
# of a is greater than the current length
# of a plus the current length of b
while len(b):
a.append(b.popleft())
Note that I'm not interested in preserving input deques, I'm only interested in having the merged one as fast as possible.
python merge deque
Exist a faster way to merge two deques than this?
# a, b are two deques. The maximum length
# of a is greater than the current length
# of a plus the current length of b
while len(b):
a.append(b.popleft())
Note that I'm not interested in preserving input deques, I'm only interested in having the merged one as fast as possible.
python merge deque
python merge deque
asked Nov 4 at 9:50
gvgramazio
3141415
3141415
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
There's no need for elementwise appending, you can just use +=:
from collections import deque
a = deque([1, 2, 3])
b = deque([4, 5, 6])
a += b
print(a)
deque([1, 2, 3, 4, 5, 6])
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
There's no need for elementwise appending, you can just use +=:
from collections import deque
a = deque([1, 2, 3])
b = deque([4, 5, 6])
a += b
print(a)
deque([1, 2, 3, 4, 5, 6])
add a comment |
up vote
1
down vote
accepted
There's no need for elementwise appending, you can just use +=:
from collections import deque
a = deque([1, 2, 3])
b = deque([4, 5, 6])
a += b
print(a)
deque([1, 2, 3, 4, 5, 6])
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
There's no need for elementwise appending, you can just use +=:
from collections import deque
a = deque([1, 2, 3])
b = deque([4, 5, 6])
a += b
print(a)
deque([1, 2, 3, 4, 5, 6])
There's no need for elementwise appending, you can just use +=:
from collections import deque
a = deque([1, 2, 3])
b = deque([4, 5, 6])
a += b
print(a)
deque([1, 2, 3, 4, 5, 6])
answered Nov 4 at 10:05
jpp
78.5k184592
78.5k184592
add a comment |
add a comment |
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
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139531%2ffastest-way-to-merge-two-deques%23new-answer', 'question_page');
}
);
Post as a guest
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
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
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