Işık Kaplan
Işık Kaplan

Reputation: 2992

How to increase all integers in all the sublists?

a = [[1,2,3,4],[5,6],[7,8,9]] to name_doesn't_matter = [[11,12,13,14],[15,16],[17,18,19]]

and the number of sublists are the result of user input so the answer should be for any given number of sublists.

Upvotes: 0

Views: 29

Answers (1)

Batman
Batman

Reputation: 8947

Use list comprehensions:

foo = [[1, 2, 3, 4], [5, 6], [7, 8, 9]]
bar = [[x + 10 for x in inner] for inner in foo]

Upvotes: 2

Related Questions