To convert from a string to a list of characters
>>> s = 'spam'
>>> t = list(s)
>>> print t
['s', 'p', 'a', 'm']
To break a string into words
>>> s = 'pining for the fjords'
>>> t = s.split()
>>> print t
['pining', 'for', 'the', 'fjords']
To convert all elements in a list to a string
>>> t = ['pining', 'for', 'the', 'fjords']
>>> delimiter = ' ' # the delimiter is a space character, so join puts a space between words
>>> delimiter.join(t)
'pining for the fjords'
References
Allen B. Downey, Think Python: How to Think Like a Computer Scientist,
http://www.greenteapress.com/thinkpython/html/index.html
Subscribe to:
Post Comments (Atom)
Mounting USB drives in Windows Subsystem for Linux
Windows Subsystem for Linux can use (mount): SD card USB drives CD drives (CDFS) Network drives UNC paths Local storage / drives Drives form...
-
I. Five different ways to answer a question II. Use SOLO strategies to explain our thinking and reasoning III. SOLO Taxono...
-
Learning levels 1, 2, and 3 Learning levels 4, 5, and 6 References http://www.cccs.edu/Docs/Foundation/SUN/QUESTIONS%20FOR%20TH...
No comments:
Post a Comment