Skip to content
Advertisement

Combine list elements to create a nested list

Given a python list with alternating values of two types:

JavaScript

How can I combine every two values to get something like this:

JavaScript

Advertisement

Answer

You can simply use range()‘s step parameter and list indexing.

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement