In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
What are the tips for dealing with lists and dictionaries in PYTHON? for this question, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
# if statement in the line print "Hello" if True else "World" > Hello# rounding down print 5.0 World 2 > print 5 to the power of 2 > 3 floating point division print .3 / .1 > 2.9999999999999996print / .1 > 2.iteration of both lists nfc = ["Packers", "49ers"] afc = ["Ravens", "Patriots"] for teama, teambin zip (nfc) simultaneously Afc): print teama + "vs." + teamb > Packers vs. Ravens > 49ers vs. Patriots# indexed list iteration teams = ["Packers", "49ers", "Ravens", "Patriots"] for index, teamin enumerate (teams): printindex, team > 0 Packers > 1 49ers > > 2 Ravens > 3 Patriots# use the following instead of numbers = [1prit 2, 3, 4, 5) even = [number for numberin numbers if number%2 = 0] # dictionary derivation teams = [Packers "," 49ers "," Ravens " "Patriots"] print {key: value for value, keyin enumerate (teams)} > > {'49erslists: 1,' Ravens': 2, 'Patriots': 3,' Packers': 0} # initialize the values of the list items = [0] * 3print items >] # convert the list to the string teams = ["Packers", "49ers", "Ravens", "Patriots"] print "," .join (teams) > 'Packers, 49ers, Ravens " Patriots'# do not use the following way: data = {'user': 1,' name': 'Max',' three': 4} try: is_admin = data ['admin'] except KeyError: is_admin = False# replace data = {' user': 1, 'name':' Max', 'three': 4} is_admin = data.get (' admin' False) answers to questions about PYTHON's tips for handling lists and dictionaries are shared here. I hope the above content can help you to a certain extent, if you still have a lot of doubts to be solved, you can follow the industry information channel to learn more related knowledge.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.