What is the traversal of iterable objects in big data
This article introduces what is the traversal of iterable objects in big data. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Items = [1, 2, 3, 4, 4, 5, and 6] results: 1 [2, 3, 3, 4, 4, 5, 5, 6] 2 [3, 4, 5, 5, 6] 3 [4, 5, 5, 6] 6 []
Method 1:
Def sum (items): # Recursive head,*tail = items print (head,tail) return head + sum (tail) if tail else head
Method 2:
Def sum (items): # unpack tail = items while tail: head,*tail = tail print (head,tail)
Method 3:
Def sum (items): # slice tail = items while tail: print (tail [: 1] [0], tail [1:]) tail = tail [1:]
Method 4:
Items = [1 list 2, items 3] def sum (items): # list method while items: print (items [0], items [1:]) items.pop (0) this is the end of the traversal of iterable objects in big data. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.