Let's say I have a list:
list = ['foo', 'bar', 'bak']
I want to split these strings into their characters so I can assign values to each character (I.E. f = 5, o = 15, and so on).
How might I decompose these lists? I was thinking of turning each element into its own list, and referring to each element as an item of that list, but I am not sure how to go about doing that.
Strings are iterable in Python, so you can just loop through them like this:
list = ['foo', 'bar', 'bak']
for item in list:
for character in item:
print(character)
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