Python mapreduce Exercises

Source: Internet
Author: User

 fromFunctoolsImportReducedefStr2Int (s):defChar2int (c):return{"0": 0,"1": 1,"2": 2,"3": 3,"4": 4,                "5": 5,"6": 6,"7": 7,"8": 8,"9": 9}[c]returnReduceLambdaX, Y:x * 10 +y, Map (Char2int, s))Print(Str2Int ("98986553"))

Title, change the string to int

1.

# using the map () function, the user entered an irregular English name, the first letter capitalized, the other lowercase canonical name.
# input: [' Adam ', ' Lisa ', ' Bart '], output: [' Adam ', ' Lisa ', ' Bart ']:
m = map (Lambda s:s[:1].upper () + s[1:].lower (), ['Adam'LISA ' ' BarT ' ])print(list (m))

The sum () function provided by 2.Python can accept a list and sum, write a prod () function that accepts a list and uses the reduce () to calculate the product:
def prod (l):     return reduce (lambda x, y:x * y, L)

# Use map and reduce to write a str2float function that converts the string ' 123.456 ' to a floating-point number of 123.456:
def Str2float (s):     return reduce (lambda x, y:x + y * (0.1 * * (len (y))), map (int, s.split ('). ')))

Python mapreduce Exercises

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.