30 seconds of python

  Back to Home

transpose

listintermediate

Returns the transpose of a two-dimensional list.

Use *lst to get the passed list as tuples. Use zip() in combination with list() to create the transpose of the given two-dimensional list.

def transpose(lst):
    return list(zip(*lst))