Skip to content Skip to sidebar Skip to footer

Creating A List Of Lists With Consecutive Numbers

I am looking for a convenient way to create a list of lists for which the lists within the list have consecutive numbers. So far I only came up with a very unsatisfying brute-typin

Solution 1:

It's not clear what consecutive numbers you're talking about, but your code translates into the following idiomatic Python:

[[] for _ inrange(4)]          # use xrange in python-2.x

Solution 2:

Don't do it this way. Put it in blocks in the first place:

blocks = [
  [ ... ],
  [ ... ],
  [ ... ],
  [ ... ]
]

Post a Comment for "Creating A List Of Lists With Consecutive Numbers"