Reputation: 39
I need to add an integer on to the end of a list. One constraint for the problem I'm solving is that I can't use any methods, so I can't use .append().
I've tried using
list = []
list += someInt
but that returns
TypeError: 'int' object is not iterable
Any help would be much appreciated!
Upvotes: 0
Views: 2920
Reputation: 3056
One more way for some more flavor :) ...IF you can't just use append
, but can use some other method (extend
) in this case
def t2():
lst = [1,2]
lst.extend([3])
print lst #prints [1, 2, 3]
Upvotes: -1