Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Regular Expressions in Python Introduction to Regular Expressions Word Length

Klemens Meyer
Klemens Meyer
5,656 Points

I have no idea what is wrong. Code works fine in workspaces. Can anybody help me , please ?

def find_words(count, data): list1=[] list2 =[] count = int(count) list1 = re.findall(r'\w+', data) for item in list1 : if len(item) >= count : list2.append(item) list2.insert(0,count) print(list2)

word_length.py
import re

# EXAMPLE:
# >>> find_words(4, "dog, cat, baby, balloon, me")
# ['baby', 'balloon']
def find_words(count, data):
  list1=[]
  list2 =[]
  count = int(count)
  list1 = re.findall(r'\w+', data)
  for item in list1 :
    if len(item) >= count :
       list2.append(item)
  list2.insert(0,count)
  print(list2)            
Klemens Meyer
Klemens Meyer
5,656 Points

should be string in place of data, but this don't fix problem.

3 Answers

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi! The challenge is asking you to return the list not print it. Also, it only wants the words, but you've inserted the count at the beginning of the list which is also causing an issue.

def find_words(count, data):
  list1=[]
  list2 =[]
  count = int(count)
  list1 = re.findall(r'\w+', data)
  for item in list1 :
    if len(item) >= count :
       list2.append(item)
  # list2.insert(0,count)
  # print(list2)            
  return list2
Klemens Meyer
Klemens Meyer
5,656 Points

Example shows count at the beginning of the list that's why I inserted it there . Thank you very much for help . :)

Megan Amendola
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Ah, I see! Let me break that down for you:

# EXAMPLE:
# This part of the example is showing the function call to show you an example
# of the info your function will be receiving
# >>> find_words(4, "dog, cat, baby, balloon, me")

# This is the output from the function, or what your function should return
# ['baby', 'balloon']
Klemens Meyer
Klemens Meyer
5,656 Points

All right, i got it now . Thanks for explanation . :)