1.2. Entry Test

1.2.1. Entry Test List of Dict

  • Assignment name: Entry Test List of Dict

  • Last update: 2020-10-01

  • Complexity level: easy

  • Lines of code to write: 6 lines

  • Estimated time of completion: 8 min

  • Solution: entry_test_listdict.py

English
  1. Use data from "Input" section (see below)

  2. Define result: list[dict]:

    • key - name from the header

    • value - measurement or species

  3. Compare result with "Output" section (see below)

Polish
  1. Użyj danych z sekcji "Input" (patrz poniżej)

  2. Zdefiniuj result: list[dict]:

    • klucz: nazwa z nagłówka

    • wartość: wyniki pomiarów lub gatunek

  3. Porównaj wyniki z sekcją "Output" (patrz poniżej)

Input
DATA = [
    ('Sepal length', 'Sepal width', 'Petal length', 'Petal width', 'Species'),
    (5.8, 2.7, 5.1, 1.9, 'virginica'),
    (5.1, 3.5, 1.4, 0.2, 'setosa'),
    (5.7, 2.8, 4.1, 1.3, 'versicolor'),
    (6.3, 2.9, 5.6, 1.8, 'virginica'),
    (6.4, 3.2, 4.5, 1.5, 'versicolor'),
    (4.7, 3.2, 1.3, 0.2, 'setosa'),
]
Output
>>> assert type(result) is list
>>> assert all(type(row) is dict for row in result)
>>> result  # doctest: +NORMALIZE_WHITESPACE
[{'Sepal length': 5.8, 'Sepal width': 2.7, 'Petal length': 5.1, 'Petal width': 1.9, 'Species': 'virginica'},
 {'Sepal length': 5.1, 'Sepal width': 3.5, 'Petal length': 1.4, 'Petal width': 0.2, 'Species': 'setosa'},
 {'Sepal length': 5.7, 'Sepal width': 2.8, 'Petal length': 4.1, 'Petal width': 1.3, 'Species': 'versicolor'},
 {'Sepal length': 6.3, 'Sepal width': 2.9, 'Petal length': 5.6, 'Petal width': 1.8, 'Species': 'virginica'},
 {'Sepal length': 6.4, 'Sepal width': 3.2, 'Petal length': 4.5, 'Petal width': 1.5, 'Species': 'versicolor'},
 {'Sepal length': 4.7, 'Sepal width': 3.2, 'Petal length': 1.3, 'Petal width': 0.2, 'Species': 'setosa'}]

1.2.2. Entry Test Endswith

  • Assignment name: Entry Test Endswith

  • Last update: 2020-10-01

  • Complexity level: easy

  • Lines of code to write: 4 lines

  • Estimated time of completion: 8 min

  • Solution: entry_test_endswith.py

English
  1. Use data from "Input" section (see below)

  2. Define result: list[str] with species names ending with "ca" or "osa"

  3. Compare result with "Output" section (see below)

Polish
  1. Użyj danych z sekcji "Input" (patrz poniżej)

  2. Zdefiniuj result: list[str] z nazwami gatunków kończącymi się na "ca" lub "osa"

  3. Porównaj wyniki z sekcją "Output" (patrz poniżej)

Input
DATA = [
    ('Sepal length', 'Sepal width', 'Petal length', 'Petal width', 'Species'),
    (5.8, 2.7, 5.1, 1.9, {'virginica'}),
    (5.1, 3.5, 1.4, 0.2, {'setosa'}),
    (5.7, 2.8, 4.1, 1.3, {'versicolor'}),
    (6.3, 2.9, 5.6, 1.8, {'virginica'}),
    (6.4, 3.2, 4.5, 1.5, {'versicolor'}),
    (4.7, 3.2, 1.3, 0.2, {'setosa'}),
    (7.0, 3.2, 4.7, 1.4, {'versicolor'}),
    (7.6, 3.0, 6.6, 2.1, {'virginica'}),
    (4.6, 3.1, 1.5, 0.2, {'setosa'}),
]
Output
>>> assert type(result) is list
>>> assert all(type(row) is str for row in result)
>>> result
['virginica', 'setosa', 'virginica', 'setosa', 'virginica', 'setosa']

1.2.3. Entry Test File

  • Assignment name: Entry Test File

  • Last update: 2020-10-01

  • Complexity level: hard

  • Lines of code to write: 15 lines

  • Estimated time of completion: 13 min

  • Solution: entry_test_file.py

English
  1. Use data from "Input" section (see below)

  2. Skip comments (#) and empty lines

  3. Extract from each line: ip, host and protocol and add to result: list[dict]

  4. Each line must be a separate dict

  5. Merge host names with the same IP

  6. IPv4 protocol address is when dot (.) is in ip address

  7. result must be list of dicts (list[dict])

  8. Compare result with "Output" section (see below)

Polish
  1. Użyj danych z sekcji "Input" (patrz poniżej)

  2. Pomiń komentarze (#) i puste linie

  3. Wyciągnij z każdej linii: ip, host i protokół i dodaj do result: list[dict]

  4. Każda linia ma być osobnym słownikiem

  5. Protokół IPv4 jest gdy kropka (.) znajduje się w adresie

  6. Scal nazwy hostów dla tego samego IP

  7. Porównaj wyniki z sekcją "Output" (patrz poniżej)

Input
DATA = """
##
# ``/etc/hosts`` structure:
#   - IPv4 or IPv6
#   - Hostnames
 ##

127.0.0.1       localhost
127.0.0.1       astromatt
10.13.37.1      nasa.gov esa.int roscosmos.ru
255.255.255.255 broadcasthost
::1             localhost
"""
Output
>>> assert type(result) is list
>>> assert all(type(row) is dict for row in result)
>>> result  # doctest: +NORMALIZE_WHITESPACE
[{'ip': '127.0.0.1', 'hosts': ['localhost', 'astromatt'], 'protocol': 'ipv4'},
 {'ip': '10.13.37.1', 'hosts': ['nasa.gov', 'esa.int', 'roscosmos.ru'], 'protocol': 'ipv4'},
 {'ip': '255.255.255.255', 'hosts': ['broadcasthost'], 'protocol': 'ipv4'},
 {'ip': '::1', 'hosts': ['localhost'], 'protocol': 'ipv6'}]