yangshun / tech-interview-handbook

💯 Curated coding interview preparation materials for busy software engineers
https://www.techinterviewhandbook.org
MIT License
119.09k stars 14.73k forks source link

Update transposition snippet (python) #634

Open pshabunia opened 9 months ago

pshabunia commented 9 months ago

zipping the matrix is a nice trick but it doesn't always produce what you need (a matrix) in a time-sensitive interview environment. The output of zip is an iterator of tuples which doesn't allow accessing elements by index. Converting the iterator of tuples to matrix takes the same amount of code as transposing the matrix itself

transposed_matrix[0][0] will raise an error TypeError: 'zip' object is not subscriptable