aneagoie / ztm-python-cheat-sheet

https://zerotomastery.io/courses/python/cheatsheet/
2.45k stars 1.35k forks source link

Matrix looping issue #16

Closed mathieugouin closed 3 years ago

mathieugouin commented 3 years ago

Hello, very nice cheat sheet by the way :)

I just found a small bug:

# Looping through a matrix by rows:
mx = [[1,2],[3,4]]
for row in range(len(mx)):
    for col in range(len(mx)):
        print(mx[row][col]) # 1 2 3 4

The column for loop should be like this:

for col in range(len(mx[0])):

It works by chance, because you matrix is 2 x 2 :)

mathieugouin commented 3 years ago

Same here:

# Transform into a list:
[mx[row][col] for row in range(len(mx)) for col in range(len(mx[0]))] # [1,2,3,4]
aneagoie commented 3 years ago

Thanks for catching this one! Would you mind submitting a pull request so you get the credit for the change?

mathieugouin commented 3 years ago

Sure no problem!

Mathieu On Dec 19, 2020 6:34 AM, "Andrei Neagoie" notifications@github.com wrote:

Thanks for catching this one! Would you mind submitting a pull request so you get the credit for the change?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/aneagoie/ztm-python-cheat-sheet/issues/16#issuecomment-748461858, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYG2PT6S2LMBTAEJDWKUTTSVSFURANCNFSM4VB7MNWQ .

mathieugouin commented 3 years ago

Refer to PR #17.

Thanks!