In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces python how to achieve two list intersection, union, difference, the corresponding elements of the relevant knowledge, detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that after reading this python how to achieve two list intersection, union, difference, the corresponding elements of the article will have a harvest, let's take a look at it.
List the intersection, union and non-a = [1,3,5,7] b = [3,5] # find the intersection of two sets (using set) intersection_list = list (set (a) .intersection (set (b)) print ("intersection:", intersection_list) # Union (using set) union_list = list (set (a) .union (set (b)) print ("Union:" Union_list) # non-differ_list = list (set (a) .difference (set (b)) print ("remove b residual values in a", differ_list) intersection: [3,5] Union: [1,3,5,7] a remove b residual values [1,7]
Note:
The set method is used above, so you need to list [set (a)] to generate a new list
Otherwise, the operation of the type 'set',set method can be used for list,np.arrary
Np.mat does not apply
List corresponding position element addition and subtraction import numpy as npa = [1,3,5] b = [2,2,2] # method 1: a+bd=np.array (a) + np.array (b) d=list (d) print ("aquib:", d) # method 2: aqumbc = [a [I] + b [I] for i in range (len (a)] print ("aquib:", c) # aLim b merge print ("Aline b merge:", ahumb) aqumb: [3, 5, 7] aqumb: [3 5, 7] A python b merge: [1, 3, 5, 2, 2, 2] this is the end of the article on "how to realize the intersection, union, difference, addition and subtraction of two lists of two lists" Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to achieve the intersection of two lists, union, difference, and the addition and subtraction of corresponding elements in python". If you want to learn more knowledge, you are welcome to follow the industry information channel.
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.