Transpose a grid · הטלת רשת
Transpose a grid
Swap the rows and columns of a grid, as if you reflected a table across its diagonal.
grid[r][c] is the item in row r and column c. The new grid has one row for each column of the old one, so loop over the column numbers first, and inside that loop collect row[col] from every row.
תובעת גריד
להחליף בין שורות ועמודות של גריד, כאילו שמרנו טבלה על פני אלכסונה.
grid[r][c] הוא הפריט בשורה r בעמודה c. הגריד החדש מכיל שורה אחת עבור כל עמודה מהישנה, ולכן יש לסרוק תחילה את מספרי העמודות, ובתוך לולאה זו לאסוף את row[col] מכל שורה.
Write transpose(grid) that turns rows into columns. grid is a list of rows, all the same length. [[1, 2, 3], [4, 5, 6]] becomes [[1, 4], [2, 5], [3, 6]]. · כתוב transpose(grid) שמומר שורות לעמודות. grid היא רשימת שורות, כולם באותו אורך. [[1, 2, 3], [4, 5, 6]] הופך ל-[[1, 4], [2, 5], [3, 6]].
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.