Homework help
John Nagle
nagle at animats.com
Tue Apr 1 13:48:52 EDT 2008
bobby.connor at gmail.com wrote:
> Hey guys
> I haev this homework assignment due today
> I don't necessarily want the answers, but need help on how to approach
> it/the steps i need to solve the problems
> Thanks
>
> # (2 Points) Write a python function howMany(item,lst) which accepts
> an item and a lst of items and returns the number of times item occurs
> in lst. For example, howMany(3,[1,2,3,2,3]) should return 2.
def howmany(item, lst) :
return(len(filter(lambda x: x==item, lst)))
>
> # (2 Points) Write a python function upTo(n) which accepts a non-
> negative number n and returns a list of numbers from 0 to n. For
> example, upTo(3) should return the list [0, 1, 2, 3].
def howmany(n) :
return(range(n+1))
That should get you started.
John Nagle
More information about the Python-list
mailing list