0

Let say this is the original list

a = [['john', 12, 15],
     ['keith', 8, 20],
     ['jane', 18, 10]]

I want to add a value 99 to each row, the expected result will be like

a = [['john', 12, 15, 99],
     ['keith', 8, 20, 99],
     ['jane', 18, 10, 99]]

Any build in function to achieve this result?

2 Answers 2

4

If you want to modify your existing lists then simply loop and append:

for l in a:
    l.append(99)

If you are fine with creating new lists then use the list-comprehension suggested by @languitar.

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

Comments

1

You can use list comprehension for this:

a = [x + [99] for x in a]

Btw. what you are using is a python list, not an array.

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.