Projects/determinate2x2.py

9 lines
241 B
Python

from typing import List
def det2x2(llist: List[List[int]])->int:
assert len(llist) == 2 and len(llist[0]) == 2, "Matrix is not 2x2"
z = list(zip(llist[0], llist[1][::-1]))
det = z[0][0]*z[0][1] - z[1][0]*z[1][1]
return det