Python – gotta love it
May 27, 2008 – 2:39 amI’ve programmed in lots of languages (have on past occasion considered myself a Smalltalk, Java, Ruby… aficionado.) But I really like Python and the mindset of the community – a smart, no-nonsense efficiency. Something simple like unit testing – you can do it by having Python execute your docstrings, which you can cut and past straight from the shell. Nice!
def largestArrayCompareToMax(array):
"""
Prints largest value in array by comparing to max - O(n) solution
>>> largestArrayCompareToMax([1,5,9,2,4,6,8,3,7])
9
"""
max = array[0]
for i in range(len(array)):
if array[i] > max:
max = array[i]
print max
if __name__ == "__main__":
import doctest
doctest.testmod()
One Response to “Python – gotta love it”
Good words.
By Sara on Oct 27, 2008