Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Regular Expressions in Python Introduction to Regular Expressions Word Length

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)            

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

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']

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