+ 2

can someone provide an example of the chain function?

10th Aug 2016, 8:11 PM
Jon L
Jon L - avatar
3 Answers
+ 4
This is an example. from itertools import accumulate, takewhile, chain nums = list(accumulate(range(8))) #declare and initialize second list nums2 = list(accumulate(range(10))) #print both lists print(nums) print(nums2) #chain function inside a list function produce a longer list that contains both elements of nums and nums2 like a chain print(list(chain (nums ,nums2)))
14th Aug 2016, 3:37 PM
Alessandro Censi
Alessandro Censi - avatar
+ 3
from itertools import chain num1=[1,2,3] num2=[2,5,7] nums=list(chain(num1, num2)) print (nums)
9th Jan 2017, 10:38 AM
Armand Dwi
Armand Dwi - avatar
0
nice😉
15th Aug 2016, 4:53 PM
Hassan
Hassan - avatar