In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "case Analysis of Python practical skills". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1 、 List:all_equal
Implementation: verify that all elements of the list are the same
Tips: use [1:] and [:-1] to compare all the elements of the list
Def all_equal (lst): return lst [1:] = = lst [:-1]
Example:
All_equal ([1, 2, 3, 4, 5, 6]) # Falseall_equal ([1, 1, 1]) # True
2 、 List:all_unique
Implementation: return true if all values in the list are unique, otherwise false
Tips: use the set set () to remove duplicates in the list and compare the length of the original list with the result
Def all_unique (lst): return len (lst) = = len (set (lst))
Example:
X = [1, Trueall_unique, 3, 4, 5, 5, 6] y = [1, Trueall_unique, 2, 3, 4, 5] False
3 、 List:bifurcate
Implementation: list values are grouped. If the filter element is true, then the corresponding element belongs to the first group, otherwise it belongs to the second group
Tips: list derivation and enumerate () based on filter elements to each group
Def bifurcate (lst, filter): return [[x for iMagne x in enumerate (lst) if filter [I] = = True], [x for iMagne x in enumerate (lst) if filter [I] = = False]]
Example:
Bifurcate (['beep',' boop', 'foo',' bar'], [True, True, False, True]) # [['beep',' boop', 'bar'], [' foo']]
4 、 List:difference
Implementation: returns the difference between two iterables
Tips: create a collection of b and use the list derivation of a to retain elements that are not in _ b
Def difference (a, b): _ b = set (b) return [item for item in an if item not in _ b]
Example:
Difference ([1,2,3], [1,2,4]) # [3]
5 、 List:flatten
Implementation: an one-time integrated list
Tips: extract each value of a sublist using a nested list
Def flatten (lst): return [x for y in lst for x in y]
Example:
This is the end of the introduction of "Python practical skills case Analysis" of flatten ([[1pyrum 2pyrm 3reagio 4], [5pyrrine 6pyror8]) # [1pyrmus 2pyrmus 3pyrrine 4,5pyrrine 6pyrmus 7pyrrine 8]. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.