Test Informed Learning with Examples

Logo

Repository with assignments using the Test Informed Learning with Examples (TILE) method to integrate testing into existing programming courses for free.

Menu

LinkedIN Community

Join our LinkedIN Community.

Cite this work

Use the following BibTeX entry to cite this work:

@INPROCEEDINGS{DVMB2023,
  author={Doorn, Niels and Vos, Tanja and Marín, Beatriz and Barendsen, Erik},
  booktitle={2023 IEEE Conference on Software Testing, Verification and Validation (ICST)}, 
  title={Set the right example when teaching programming: Test Informed Learning with Examples (TILE)}, 
  year={2023},
  volume={},
  number={},
  pages={269-280},
  doi={10.1109/ICST57152.2023.00033}
}

Zipping sequences into tuples

zip is a function that is predefined in Python. It takes two or more sequences and intersperses them. The name of the function refers to a zipper, since it intersperses two rows of teeth.

This example zips a string and a list:

>>> s = 'abc'
>>> t = [0, 1, 2]
>>> zip(s, t)
<zip object at 0x7f7d0a9e7c48>

The result is a zip object that contains pairs that can be iterated over. The most common use of zip is in a for loop:

>>> for pair in zip(s, t):
...     print(pair)
...
('a', 0)
('b', 1)
('c', 2)

We are going to write a my_zip function that does not return a zip object, but directly the list with the tuples. You can assume that the two sequences it receives have the same number of elements:

>>> s = 'abc'
>>> t = [0, 1, 2]
>>> mi_zip(s,t)
[('a', 0), ('b', 1), ('c', 2)]
>>> s = (1,2,3)
>>> t = [4,5,6]
>>> mi_zip(s,t)
[(1, 4), (2, 5), (3, 6)]

Don’t forget to test your function with pytests.