0

How to add list m and k so to get a list ["ogay","veroay","heretay"] ?

string=input().replace(" ",",").split(",") h=[j.replace(j[0],"") for j in string] m=[i[0]+"ay" for i in string] k=[n+l for n in h for l in m] # k = ["o","ver","here"] # m = ["gay","oay","tay"]

18th Mar 2023, 2:10 PM
Vaibhav Pandey
11 Antworten
+ 3
Assuming <k> and <m> contain string, and have equal number of items; you can zip <k> and <m> then use f-String to glue chunks taken from each `list`
18th Mar 2023, 2:27 PM
Ipang
+ 1
Ipang Don't know how to do it bro
18th Mar 2023, 2:30 PM
Vaibhav Pandey
18th Mar 2023, 2:44 PM
Ipang
+ 1
Ipang Thanks bro i understand it but it's creating tuple it's not adding it.Could you tell me how to use the f-string to glue it
18th Mar 2023, 2:53 PM
Vaibhav Pandey
+ 1
Ipang Nah bro thanks i did it
18th Mar 2023, 3:01 PM
Vaibhav Pandey
+ 1
Okay good job! Here's the f-String reference just in case ... https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-f-strings/
18th Mar 2023, 3:03 PM
Ipang
+ 1
Easy bro, just use join() method from `str` class result = " ".join( lst ) You can replace the space " " with any string you want to use for gluing the `list` elements ...
18th Mar 2023, 3:12 PM
Ipang
+ 1
Thanks bro
18th Mar 2023, 3:12 PM
Vaibhav Pandey
0
Ipang Hey bro could you tell me how to convert a list into str i forgot
18th Mar 2023, 3:04 PM
Vaibhav Pandey
0
Give me list example, and the expected string result. I''ll see if I could help ...
18th Mar 2023, 3:05 PM
Ipang
0
Ipang lst=["hey","bro","hello"] Into this hey bro hello
18th Mar 2023, 3:07 PM
Vaibhav Pandey