+ 2
can someone provide an example of the chain function?
3 odpowiedzi
+ 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)))
+ 3
from itertools import chain
num1=[1,2,3]
num2=[2,5,7]
nums=list(chain(num1, num2))
print (nums)
0
nice😉