# Help Re: Python

Hey guys
I have a homework assignment today and need serious help with it. I don’t necessarily want the answers, but rather the steps or ideas to solve the problem
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.

• (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].

• (2 Points) Write a python function duplicate(lst) which accepts a lst of items and returns a list with the items duplicated. For example, duplicate([1,2,2,3]) should return the list [1, 1, 2, 2, 2, 2, 3, 3].

• (2 Points) Write a python function dotProduct(a,b) which accepts two lists of integers a and b that are of equal length and which returns the dot product of a and b. I.e., the sum a0 * b0 + … + an-1 * bn-1 where n is the length of the lists. For example:
dotProduct([1,2,3],[4,5,6]) is 14 + 25 + 3*6 = 4 + 10 + 18 = 32

• (2 Points) A pair (exp0, exp1) is a combination of expressions that are attached together by their joint membership in the pair. For example: >>> (1+2, ‘This’)
(3, ‘This’)
A component of a pair can be obtained using an index in brackets as with lists (and strings!). For example: >>> (33,44)[0]
33
Write a function zip(lst1, lst2) such that zip accepts two equal length lists and returns a list of pairs. For example, zip([‘a’, ‘b’, ‘c’], [10, 20, 30]) should evaluate to the list [(‘a’, 10), (‘b’, 20), (‘c’, 30)].

• (2 Points) Write a function unzip(lst) such that unzip accepts a list of pairs and returns two lists such that lst == zip(unzip(lst)). For example, unzip([(‘a’, 10), (‘b’, 20), (‘c’, 30)] should evaluate to the pair ([‘a’, ‘b’, ‘c’], [10, 20, 30]).

• (2 Points) Write a python function isAscending(lst) which accepts a non-empty list of integers and returns True if the numbers in the list are in ascending order. Otherwise it should return False. For example, isAscending([1]) should evaluate to True while isAscending([1,2,2]) should return False.

Without providing the answers there really is no way to give you any help. These are all pretty basic requests. Coming up with test examples is the arguably the hardest part of programming. Take those examples and use them as your psuedo code, and right the basic functions using them as a starting point. The only realy insight I could give you, not giving away the entire answer, would be that for the first two you’re going to want a counter in your function. That’s as much of a hint I can give without giving you the answers.

Also, this isn’t the best place to just sign up for help with your homework (post count: 1 and all). There are better places to find this info. Got a blender scripting issue? Some can help. Got a blender question? Most can help. Need help with your programming homework…sign up in a programming forum…not an art forum. Just a suggestion.