# Editor: Shanlong l = [2, 3, 4, 5, 6,7 for in# get a new list L1, each element in the new list is the square of the value of each element in L /c6>printforif i > Max]# filter out values greater than 40 in L1 and sum print(sum (L1))
Above, there's nothing to say
#edited by: ShanlongShares = { 'IBM': 36.6, 'Lenovo': 27.3, 'Huawei': 40.3, 'Oldboy': 3.2, 'Ocean': 20.1}#question one: A list of stock names with a stock price greater than 30L = [i forIinchSharesifFloat (shares[i]) >30]Print(L)#question two: Find out the total price of all stocksL1 = [I forIinchshares.values ()]Print(SUM (L1))
The above, or special, nothing to say
#edited by: Shanlong#There are two lists of the names of the old boys who enrolled in the Linux and Python classes.Linux = ['Steel Bullets','Small Gecko','Little Tiger ratio','Alex','Wupeiqi','Yuanhao']python= ['Dragon','Steel Bullets','zhejiangF4','Little Tiger ratio']#question one: Get a list of students who sign up for both Linux and PythonL = [i forIinchLinuxifIinchPython]Print(L)#question two: Get a list of students who only sign up for Linux and not sign up for PythonL = [i forIinchLinuxifI not inchPython]Print(L)#question three: Get a list of students who only sign up for Python and not enroll in LinuxL = [i forIinchPythonifI not inchLinux]Print(l)
Above, there's still nothing to say
It's a wordless ending today, Battambang.
Python Exercises-builder expressions-filtering and operations