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!
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
John Nguyen32 Points
Lets say I wanted to make a def that takes only the first initials of a word in a list. How would I do that?
For example listName = ['Bob' , 'Joe' , Ashley'] def first_letter(listName): //returns [B,J,A]
William LiCourses Plus Student 26,867 Points
def first_letter(listName): return [i for i in listName]
But if you really want to do it in recursion
# recursive version def first_letter(listName): if len(listName) == 0: # base case return  else: return [listName] + first_letter(listName[1:]) # recursive call
Seriously, list comprehension is way better here.