l = ['1','2','3']
goal = ['<li>1</li>','<li>2</li>']
How can I get goal from l?
I'm playing with list comprehensions but it's messy!
Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.
join() is an inbuilt string function in Python used to join elements of the sequence separated by a string separator. This function joins elements of a sequence and makes it a string. Syntax: string_name.join(iterable)
Use str. join() to join a list of strings. Call str. join(iterable) to join each element in the list of strings iterable with each element connected by the separator str .
Try string formatting and list comprehension, like so.
goal = ['<li>{0}</li>'.format(x) for x in l]
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With