+13

What is the use of 'chain' function in itertools in python?

Can you demonstrate with an example?

6/25/2019 8:16:34 AM

SWETA X

8 Answers

New Answer

+4

I have made a code you can check it out:) https://code.sololearn.com/c1Y632q5Kj2b/?ref=app If you feel difficulty in understanding the difference between iterator and iterable then you can check this link:) https://www-geeksforgeeks-org.cdn.ampproject.org/v/s/www.geeksforgeeks.org/python-difference-iterable-iterator/amp/?amp_js_v=a2&amp_gsa=1&usqp=mq331AQA#referrer=https%3A%2F%2Fwww.google.com&amp_tf=From%20%251%24s&ampshare=https%3A%2F%2Fwww.geeksforgeeks.org%2Fpython-difference-iterable-iterator%2F

+8

Ayush Sinha Thank you so much, I understood now!🤗😊😊😊🤗

+4

https://code.sololearn.com/cu407xW178N2/?ref=app

+3

chain(list_a,list_b) returns an iterator which has items of first list and the second list after that. Its an option for you to use it for example when you have 2 big list and you don’t want to copy them in memory or lots of other uses... https://code.sololearn.com/cD3R3Vxp4Tk0/?ref=app

+2

SWETA X🔥, 😄😄😄👍👍

+1

Pls i do have a quiz python program on my pc. The only problem that i have, is i do not know how to calculate total scores for the quiz program

+1

So if use, For loop, to iterate each item in the 2nd list..and use list.append() to add it to the 1st list..will it use a lot of memory to do so?

0

Why you're using itertools for joining two list?.. We can do it simply with list.append..