简体   繁体   中英

How to convert a list of words into multiple sentences in python

Eg: Input: Name: ['FirstName','LastName','FirstNameLastName'] Customer Account Number: ['Customer', 'Account', 'Number', 'Customer Account', 'Customer Number', 'Customer Account Number'] output: FirstNameLastName Customer Account Number

Well if you have a defined pattern to the arrays like:

index 0: first name index 1: last name index 2: fullName

to the first array, and something like it to the second. You can just add the strings together to the output.

There are some ways to do it, using python, usually you'll prefer to use fstrings.

On the exemple you settled would be like this:

output = f'{name[2]} {customer_account_number[5]}'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM