Iterate over two arrays simultaneously

You can use zip(), which creates a sequence of pairs from the two given sequences: let strArr1 = [“Some1”, “Some2”] let strArr2 = [“Somethingelse1”, “Somethingelse2”] for (e1, e2) in zip(strArr1, strArr2) { print(“\(e1) – \(e2)”) } The sequence enumerates only the “common elements” of the given sequences/arrays. If they have different length then the additional … Read more

Customizing unittest.mock.mock_open for iteration

The mock_open() object does indeed not implement iteration. If you are not using the file object as a context manager, you could use: m = unittest.mock.MagicMock(name=”open”, spec=open) m.return_value = iter(self.TEST_TEXT) with unittest.mock.patch(‘builtins.open’, m): Now open() returns an iterator, something that can be directly iterated over just like a file object can be, and it’ll also … Read more