I have a long string of characters which I want to split into a list of the individual characters. I want to include the whitespaces as members of the list too. How do I do this?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
you can do:
spaces will be treated as list members (though not grouped together, but you didn't specify you needed that)
Here some comparision on string and list of strings, and another way to make list out of string explicitely for fun, in real life use list():
This isn't an answer to the original question but to your 'how do I use the dict option' (to simulate a 2D array) in comments above:
Tuples, being immutable, make perfectly good dictionary keys. Cells in the grid don't exist until you assign to them, so it's very efficient for sparse arrays if that's your thing.