[Tutor] Python Word Problems(Student) MORE ISSUES
bob gailer
bgailer at gmail.com
Thu Oct 6 12:43:43 EDT 2016
On 10/6/2016 10:15 AM, Zeel Solanki wrote:
> def filter_long_words(words, n):
> for x in words.split():
> return filter(lambda x: len(x) > n, words)
>
> print filter_long_words(raw_input("Enter a list of words with spaces in
> between."), raw_input("Enter a number."))
raw_input() always returns a string. When you enter a number (say, 5) it
will be a string ("5").
use int() to convert that string to numeric.
But there are more issues. The function logic is misleading: you can
remove the line beginning with "for". the loop will get the first word,
appply filter (ignoring the word), then the function will stop.
"However , if i replace the raw_inputs with any given list and a number
in the editor" Exactly what do you enter for a list?
Remember that anything you enter in the editor for words and n must be a
string. Your function will give incorrect results.
More information about the Tutor
mailing list