What is the use of 'chain' function in itertools in python? | Sololearn: Learn to code for FREE!

+11

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

+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

SWETA Xπ₯, πππππ

+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

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

0

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

0

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?