简体   繁体   中英

How would you make a script to take out information from a list of string, and reinsert it into another list of strings?

I am trying to figure out how to write a script that takes a list of strings, takes out certain information from that list, and re-inserts it into a different formatted string

Example:

"Hello, I am NAME1, I am from LOCATION, and I am GENDER"

to

"Hello, I'm from LOCATION, Im GENDER, my name is NAME1" (Taking information from a set position and reinputting it into a different position)

given = "Hello, I am NAME1, I am from LOCATION, and I am GENDER"
data = given.replace("and", "").split(", ")
output = f"{data[0]}, {data[2]}, {data[3]}, and {data[1]}"
print(output)
>> Hello, I am from LOCATION,  I am GENDER, and I am NAME1

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