November 20th, 2012, 07:02 PM
I have been promted with this question and have been throughly stumped... Please help, Thanks!
Write an algorithm for each of the following python operations and test you algorithm by writing a it up in a suitable function. You are not allowed to use the corresponding Python method to implement your function. a. count(myList, x) (like myList.count(x)) b. isin(myList, x) (like x in myList)) c. index(myList, x) (like myList.index(x)) d. reverse(myList) (like myList.reverse()) e. sort(myList) (like myList.sort())
November 20th, 2012, 07:58 PM
Here's an example.
A doctest providing supporting evidence that
the function might be correct.
>>> a.count('f') == count(a,'f')
# longer, but still probably shorter than your version, that is, if you bothered to write a solution
occurrences = 0
for obj in L:
occurrences += obj == o
# short form
return sum(obj == o for obj in L)
[/code] are essential for python code and Makefiles!
November 21st, 2012, 03:40 PM
mylist = list('abcde')
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
November 22nd, 2012, 12:22 AM
Lucky for me I wrote a sorting function today, because I wanted to sort 2 lists with corresponding indexes, Here it is:
it sorts highest to lowest.
temp =