List conversion

list, python

Solution

In response to further comment from questioner, two answers:

# Original grid
grid = [[1.1, 1.2, 1.3, 1.4, 1.5],
 [2.1, 2.2, 2.3, 2.4, 2.5],
 [3.1, 3.2, 3.3, 3.4, 3.5],
 [4.1, 4.2, 4.3, 4.4, 4.5],
 [5.1, 5.2, 5.3, 5.4, 5.5]]


# Window function to return sequence of pairs.
def window(row):
    return [(row[i], row[i + 1]) for i in range(len(row) - 1)]

ORIGINAL QUESTION:

# Print sequences of pairs for grid
print [window(y) for y in grid]

UPDATED QUESTION:

# Take the nth item from every row to get that column.
def column(grid, columnNumber):
    return [row[columnNumber] for row in grid]


# Transpose grid to turn it into columns.
def transpose(grid):
    # Assume all rows are the same length.
    numColumns = len(grid[0])
    return [column(grid, columnI) for columnI in range(numColumns)]


# Return windowed pairs for transposed matrix.
print [window(y) for y in transpose(grid)]

Problem

I am looking for a way to convert a list like this ``` [[1.1, 1.2, 1.3, 1.4, 1.5], [2.1, 2.2, 2.3, 2.4, 2.5], [3.1, 3.2, 3.3, 3.4, 3.5], [4.1, 4.2, 4.3, 4.4, 4.5], [5.1, 5.2, 5.3, 5.4, 5.5]] ``` to something like this ``` [[(1.1,1.2),(1.2,1.3),(1.3,1.4),(1.4,1.5)], [(2.1,2.2),(2.2,2.3),(2.3,2.4),(2.4,2.5)] ......................................... ```

Original source