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 Python Comprehensions

YURI PAPINIAN
YURI PAPINIAN
11,838 Points

Is it possible?

Can I solve this problem by only using comprehension lists?

Given an array of ints, return the number of 9's in the array.

array_count9([1, 2, 9]) → 1 array_count9([1, 9, 9]) → 2 array_count9([1, 9, 9, 3, 9]) → 3

2 Answers

Steven Parker
Steven Parker
231,248 Points

Would combining one with a "len" function count?

array_count9(a):
    return len([n for n in a if n==9])
YURI PAPINIAN
YURI PAPINIAN
11,838 Points

Thank you. I really appreciate your help.