python string to array
>>> text = 'a b c'
>>> text = text.split(' ')
>>> text
[ 'a', 'b', 'c' ]
python string to array
>>> text = 'a b c'
>>> text = text.split(' ')
>>> text
[ 'a', 'b', 'c' ]
convert string to list python
# To split the string at every character use the list() function
word = 'abc'
L = list(word)
L
# Output:
# ['a', 'b', 'c']
# To split the string at a specific character use the split() function
word = 'a,b,c'
L = word.split(',')
L
# Output:
# ['a', 'b', 'c']
string to list python
l = list('abcd') # ['a', 'b', 'c', 'd']
l = map(None, 'abcd') # ['a', 'b', 'c', 'd']
l = [i for i in 'abcd'] # ['a', 'b', 'c', 'd']
import re # importing regular expression module
l = re.findall('.', 'abcd')
print(l) # ['a', 'b', 'c', 'd']
python3 create list from string
input = ['word1, 23, 12','word2, 10, 19','word3, 11, 15']
output = []
for item in input:
items = item.split(',')
output.append([items[0], int(items[1]), int(items[2])])
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us