+ 5

Python

I wanna read the string and make it to list .reading string depends up on input of the user

17th Nov 2020, 2:30 PM
Ajith
Ajith - avatar
16 Antworten
+ 6
n = input() for i in range(0,n): List=[] Str=input() List.append(str) print(list) ## output should be like ['a','b'] ## but I'm getting ['a'] ['b'] When n=2
17th Nov 2020, 3:45 PM
Ajith
Ajith - avatar
+ 4
Tq guys
17th Nov 2020, 5:34 PM
Ajith
Ajith - avatar
+ 3
n = int(input()) while n > 0: list = str(input()) n-=1 print(list(list) Output should be in list eg['gah',faha] # n=2
17th Nov 2020, 2:32 PM
Ajith
Ajith - avatar
+ 3
Ajith could you please reframe your question? I really do not know how to help here. Are you trying to split the second input based on the first input? Eg. Input: 3 "Reframe your question properly" Output: ["Reframe", "your", "question"]
17th Nov 2020, 3:40 PM
Tomiwa Joseph
Tomiwa Joseph - avatar
+ 3
print (input().split(" ")) Read a string split it by spaces Input : a b Output ['a','b']
18th Nov 2020, 7:17 AM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar
+ 2
# input example # >>2 # >>gah # >>faha n = int(input()) list = [] while n > 0: list.append(input()) n -= 1 print(list) # Output: ['gah','faha']
17th Nov 2020, 4:05 PM
JaScript
JaScript - avatar
+ 1
Ajith take this list=[] outside the loop then check it it will work otherwise your code was correct
18th Nov 2020, 3:01 AM
Shivang Shirvani
+ 1
t = input().split() for index, word in enumerate(t): for char in word: if char.isalnum() == False: t[index] = word.replace(char, "") print(t) # You should get a list of words and numeric strings without special characters.
18th Nov 2020, 8:21 PM
Md. Niamul Ahad Chowdhury
Md. Niamul Ahad Chowdhury - avatar
0
Я Украйнець. From Ukraine no speak English.
17th Nov 2020, 9:16 PM
Sodar
Sodar - avatar
0
Yes!
17th Nov 2020, 9:17 PM
Sodar
Sodar - avatar
0
list = list (input()) print (list)
19th Nov 2020, 8:49 AM
yingSSS['book'=="本"]
0
n = int (input()) print (list[:n])
19th Nov 2020, 9:17 AM
yingSSS['book'=="本"]
0
Я українець
19th Nov 2020, 1:48 PM
Sodar
Sodar - avatar
0
instring = str(input()) inlist = list (instring) #this converts each character into elements of list inwords = instring.split() #this converts each word in the string into elemnts of list print (inlist) print (inwords) example: for input “ Hi all”, the output will be [‘H’, ‘i’, ‘ ‘, ‘a’, ‘l’, ‘l’,] [‘Hi’, ‘all’]
8th Dec 2020, 6:49 AM
Sandhya Raghuraman
0
SHE SHE
27th Dec 2020, 8:28 PM
Shreya Srivastava