Python first letter converted to uppercase function

Source: Internet
Author: User

Now there is a need:

Assuming that the user entered the English name is not standard, not according to the first letter capitalization, subsequent letter lowercase rules, please use the map () function, a list (including a number of nonstandard English names) into a list containing the canonical English name:

Input: [' Adam ', ' LISA ', ' BarT ']
Output: [' Adam ', ' Lisa ', ' Bart ']


The original idea was to separate the characters, the first to uppercase, the rest to lowercase:

def format_name (s): Return "%s"% (S[:1].upper () + str (s[1:].lower ())) print map (format_name, [' Adam ', ' LISA ', ' BarT ')


Later on, there is a function to convert the initial letter to uppercase (capitalize):

def format_name (s): Return s.capitalize () print map (format_name, [' Adam ', ' LISA ', ' BarT ')


Python first letter converted to uppercase function

Related Article

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.