I'm currently learning Python and I need to write a program which determines the word which appears the most times in a poem. Problem which is troubling me is about parsing a lines of a poem into a SINGLE list containing words of the poem. When I solve it i will have no trouble determining the word which appears the most times.
I can access the lines of the poem by calling input() repeatedly, and the last line contains the three characters ###.
So, i wrote:
while True:
y = input()
if y == "###":
break
y = y.lower()
y = y.split()
and for input:
Here is a line like sparkling wine
Line up now behind the cow
###
got result:
['here', 'is', 'a', 'line', 'like', 'sparkling', 'wine']
['line', 'up', 'now', 'behind', 'the', 'cow']
If i try to call y[0], i get:
here
line
How can I concatenate two lists within same variable, or how can I assign every line to different variable?
Any hint is appreciated. Thanks.
y
is variously a string, a lowercased string, and finally a list.) is a bad idea, as it makes your code more confusing. It would be better to write eginputline = input()
,if inputline == "###":
,lowercased = inputline.lower()
,words = lowercased.split()
. If you don't do this kind of thing, you may often find that a variable contains something quite different than you thought when you scanned the code. – kampu 19 hours ago