+ 13
How to split user input in python?
For example : i want to split golden to 'g','o','l','d','e','n'.... THANK YOU!
26 Answers
+ 72
inp = input("Your input here")
splitted = list(inp)
Now splitted is a list with values like this :-
Suppose I gave input as Sololearn :-
splitted = ['S','o','l','o','l','e','a','r','n']
+ 18
@Ace :- split() doesn't work here
For example :-
a = "Nikhil"
b = a.split()
print(b)
would just print ['Nikhil']
It doesn't split.
+ 9
Nikhil split() function splits a string by spaces into words, am I right?
+ 4
St=[]
St=input ("enter a string")
For x in st:
Print (st[0::])
+ 3
U could try the .extend() method
For example
a= "Nikhil"
b= a.extend()
+ 3
If you want it in one line use:
var1 = input()
var2 = list(var1)
print(var2)
Or if you want it in separate lines:
var1 = input()
for var2 in var1:
print(var2)
+ 2
If you mean a string you can split strings in python they are a form of list
+ 2
Why dont you use for loop in compination with list
For example:
Word = input()
Split_word = []
For i in word:
Split_word.append(i)
This works better and simple
👌🏻
+ 2
love=input("insert your verb")
splitted=list(love)
print(splitted)
My Input = i love universe
["I","l","o","v","e", im lazy etc.....]
+ 2
#include <iostream>
using namespace std;
int main() {
int count = 300;
int time;
cin >> time;
count *= time;
cout << count << endl;
return 0;
}
+ 1
inp = input("Your input here")
splitted = list(inp)
Here I'm using, Ritviz:-
splitted = ['R','i','t','v','i','z']
+ 1
text = input()
stext= [x for x in text]
print(stext)
+ 1
Input=(‘x’)
Splitted=li’(x)
+ 1
Vshsn
+ 1
name= input (what's yourname)
+ 1
Use list function
0
Put \n Before them
0
Just use ..
splitted = ['S','o','l','o','l','e','a','r','n']
0
Use split() function
0
You can use `list()` function,
user_inp = input("enter input: ")
splitted_string = list(user_inp)
Now print the splitted_string variable to the desired output
print (splitted_string)