Python diary----2017.8.1

Source: Internet
Author: User

Built-in functions:

Homework:

3. Use map to process the list of strings and turn everyone in the list into SB, for example ALEX_SB
name = [' Alex ', ' Wupeiqi ', ' Yuanhao ', ' Nezha ']
def AD (L):
Return L[:len (L)]+ ' _SB '
Print (List (map (AD, name)))
****************************************************************************
4. Use the filter function to process the list of numbers and filter out all the even number in the list
num = [1,2,3,4,5,6,7,8]
Def ou (NUM1):
return NUM1% 2 = = 0
Print (List (filter (ou,num)))
****************************************************************************
5. Feel free to write a file with more than 20 lines
Run the program, read the contents into memory first, and store it in a list.
Receive user input page number, each page 5, output only when the content of the page

L=[]
f = open (' Test ', ' R ', encoding= ' utf-8 ')
L.append (F.read ())
A = L[0].split (' \ n ')
F.close ()
page = Int (input (' page>> '). Strip ())
Print (A[page*5-5:page*5])
For I in range (len (b)//5+1):

****************************************************************************

# 6. As follows, each dictionary name corresponds to the stock name, the shares corresponds to how many shares, price corresponds to the stock prices
Portfolio = [
{' name ': ' IBM ', ' shares ': +, ' price ': 91.1},
{' name ': ' AAPL ', ' shares ': +, ' price ': 543.22},
{' name ': ' FB ', ' shares ': $, ' Price ': 21.09},
{' name ': ' HPQ ', ' shares ': +, ' price ': 31.75},
{' name ': ' YHOO ', ' shares ': $, ' Price ': 16.35},
{' name ': ' ACME ', ' shares ': +, ' price ': 115.65}
]
Prices = [{' name ': item[' name '], ' prices ': item[' shares ']*item[' price ']} for item in portfolio]
Print (prices)
#
6.1. Calculate the total price of each stock purchased
L=[]
For I in range (len (portfolio)):
# Print (i)
Print (portfolio[i][' name '], ' Total price%s '% (portfolio[i][' shares ']*portfolio[i][' prices '))
L.append (portfolio[i][' price ')
Print (L)

# 6.2. Filter out the stock with a unit price greater than 100

def money (Qian):
Return qian > 100

Print (List (filter (money,l)))

Python diary----2017.8.1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.