Add a list and an iterator to form a new list

Viewed 102

I tried:

a_list = [1,2,3]
b_list = [4,5]
...

call_function(a_list + iter(b_list))  # TypeError

Is there a better code than this:

a_list = [1,2,3]
b_list = [4,5]
...

new_list = a_list[:]
new_list += iter(b_list)  # no TypeError?
call_function(new_list)

Consider any iterator, I'm using islice in place of iter.

4 Answers
Related