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


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

Can you demonstrate with an example?

6/25/2019 8:16:34 AM


8 Answers

New Answer


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


Ayush Sinha Thank you so much, I understood now!πŸ€—πŸ˜ŠπŸ˜ŠπŸ˜ŠπŸ€—




SWETA XπŸ”₯, πŸ˜„πŸ˜„πŸ˜„πŸ‘πŸ‘


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


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


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


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?