What would be your preferred way to concatenate strings from a sequence such that between every two consecutive pairs a comma is added We now want to convert comma_string to a list. That is, how do you map, for instance, ['a', 'b', 'c'] to 'a,b,c'?
blond jock by sknuh on DeviantArt
I discussed two solutions to the given problem using the split() method, using list comprehension.
We'll explore the most efficient and pythonic methods, using str.split(), str.join(), list comprehensions, and map()
The str.split() method is the primary tool for converting a delimited string into a list The my_str.split(',') splits the string by commas and constructs a list of substrings. This format is commonly used to represent lists or arrays of data For example, consider the string “apple,banana,orange”.
If you do not need arrays, and only want to look by index at your characters, remember a string is an iterable, just like a list except the fact that it is immutable: In this tutorial, we will learn how to convert a comma separated string to a list in python So let’s dive right into it