Reputation: 47
I am trying to return a sentence length <=
of a list index using the split()
method. If i input the exact length of a certain index, this works but <
doesn't seem to do anything. Here is my code:
stories = [['With bloody hands, I say good-bye.'],
['TIME MACHINE REACHES FUTURE!!! ... nobody there ...'],
["Not In My Job Description: Make sure it's done by the end of the day Jones.\nBut, sir, it's not in my ....\nJust do it, and remember, no blood."]]
def len_sentence():
search = int(input("Enter int"))
for i in stories:
len1 = (i[0][0:].split(' '))
if len(len1) <= search:
print(i)
len_sentence()
User input of integers 1-5 returns nothing. If I replace <=
with >=
this works. Why doesn't <
do anything?
Upvotes: 0
Views: 67
Reputation: 5532
The inputs you're trying are too small. The shortest story you have there is 6 words long, so inputs 1-5 won't match anything. The code looks fine to me though, it's just your search inputs.
Upvotes: 2