Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the traversal of iterable objects in big data

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report