Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use iterative tools in python

Shulou Source: shulou.com Published: 2022-06-01 04:35:10 09月12日 Update

This article will explain in detail how to use the iterative tools in python. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Iterative tool

Like the collections library, there is another library called itertools, which is really efficient for solving certain problems. One of the use cases is to find all the combinations, which can tell you all the impossible combinations of the elements in a group.

From itertools import combinationsteams = ["Packers", "49ers", "Ravens", "Patriots"] for game in combinations (teams, 2): print game > ('Packers',' 49ers') > ('Packers',' Ravens') > ('Packers',' Patriots') > ('49ersgiving,' Ravens') > ('49ersgiving,' Patriots') > > ('Ravens',' Patriots') False = = True

This is an interesting thing compared to practical techniques. In python, True and False are global variables, so:

False = Trueif False: print "Hello" else: print "World" > Hello on "how to use iterative tools in python" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: Tools iterations articles practical more combinations good interesting elements globals content variables practical techniques techniques articles methods knowledge this is question reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei MySQL Shulou Tech Info MariaDB