# Data Structures and Algorithms in Python | Arrays and Strings

In this series and in the next few weeks, I will show you Data Structures and Algorithms in Python by some classic interview solutions. Please take a pen, whiteboard, and your laptop. Let’s start learning!

Cheat sheet to Arrays and Strings. And some heads up for you.

# Creating a Matrix in Python without numpy

`new_matrix  = [ [None]*height ] *  width`

This way, all the inner list will be pointed to the same address, i.e.

`test_list = [[]]*5id(test_list) == id(test_list)`

`new_matrix = []i = 0while i < width:    new_matrix.append([]) # add a row    j = height - 1    while j >= 0:        new_matrix[i].append(matrix[j][i])`

# ‘in-place’ function

When doing unittest for ‘in-place’ function, remember to deepcopy the test set for looping tests, i.e.

`from copy import deepcopyfor (_input, _output) in  self.test_cases:    _input = deepcopy(_input) # don't forget this line, because it changes original input that make your right answer to be wrong`

or

`for text, expected in self.test_cases:    _input = deepcopy(text) # don't forget this line, because it changes original input that make your right answer to be wrong    for func in self.testable_functions:        start = time.perf_counter()        func(_input)        assert(            _input == expected        ), f'{func.__name__} failed for value: {text}, output={_input}, expected={expected}'`

or

`for (_input, _output) in test_cases:    _input_copy = _input.copy()    assert zero_matrix(_input_copy) == _output`

See example

Test your script: Hsiang | PyScript Hello World (chienhsiang-hung.github.io)