[Tutor] Python Word Problems(Student)

Zeel Solanki 12306 at smcdsb.on.ca
Thu Oct 6 10:15:02 EDT 2016


Hello,
I am a grade 11 high school student and I am having a hard time solving the
problem below. I have been stuck on it for days and I would like some
guidance from you.

The Problem:
Write a function filter_long_words() that takes a list of words and an
integer n and returns the list of words that are longer than n.

What I have written:
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."))

My problem:
Every time i input a list and then the number, it print an empty list.
However , if i replace the raw_inputs with any given list and a number in
the editor, it works and gives me the list of words that are longer than
the number.

Please and thank you for your help.

-- 
This is a student email account managed by Simcoe Muskoka Catholic District 
School Board. The contents of this email are governed by the laws of the 
state and the board policies of the school district.


More information about the Tutor mailing list