Exercism: Matrix (Python)

输入一个文本矩阵,返回一个简单的矩阵类,可以返回行或列。很简单,中规中矩。

class Matrix:
    def __init__(self, matrix_string):
        rows = matrix_string.split("\n")
        self.__matrix = [list(map(int, row.split(" "))) for row in rows]
    def row(self, index):
        return self.__matrix[index-1]
    def column(self, index):
        return [row[index-1] for row in self.__matrix]

评论

此博客中的热门博文

拜厄练习曲44, 45

Exercism: Word Count (Python)

pygame Alevel 项目