0

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!

1
  • 1
    have you done any research on your own before asking this question? Commented Oct 23, 2015 at 1:13

2 Answers 2

3

How about lst = lst + [someInt].

Sign up to request clarification or add additional context in comments.

1 Comment

edited to not use list, as list is a function.
-1

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.