Is there a way to, instead of duplicating code, to either print the desired number of rows from a list (from user input) or print all items in the list?
print_list( input ):
f = open('pickle.dat', "r")
L = cPickle.load(f)
f.close()
for i in range( input=len(L) ):
print 'L[i] = ', L[i]
It doesn't seem like I can set input=len(L) in the for loop or in the method header. Ideally, I'm trying to attain the following behavior:
>>> L = [ 'A', 'B', 'C', 'D', 'E' ]
>>> do_something (3)
L[0] = A
L[1] = B
L[2] = C
>> do_something()
L[0] = A
L[1] = B
L[2] = C
L[3] = D
L[4] = E
Also, if desired_items > len(L), I'd like to default to all items in the list as well:
>> do_something(100)
L[0] = A
L[1] = B
L[2] = C
L[3] = D
L[4] = E
Thanks for any help!