Assignments

class gradelib.Assignments(names: Sequence[str])

A sequence of assignments.

Behaves essentially like a standard Python list of strings, but has some additional methods which make it faster to create groups of assignments.

__add__(other) Assignments

Concatenates two collections of Assignments.

containing(substring: str) Assignments

Return only those assignments containing the substring.

Parameters:

substring (str) – The substring to search for.

Returns:

Only those assignments containing the substring.

Return type:

Assignments

ending_with(suffix: str) Assignments

Return only those assignments ending with the suffix.

Parameters:

suffix (str) – The suffix to search for.

Returns:

Only those assignments ending with the suffix.

Return type:

Assignments

group_by(to_key: Callable[[str], str]) dict[str, Assignments]

Group the assignments according to a key function.

Parameters:

to_key (Callable[[str], str]) – A function which accepts an assignment name and returns a string that will be used as the assignment’s key in the resulting dictionary.

Returns:

A dictionary mapping keys to collections of assignments.

Return type:

dict[str, Assignments]

Example

>>> assignments = gradelib.Assignments([
... "homework 01", "homework 01 - programming", "homework 02",
... "homework 03", "homework 03 - programming", "lab 01", "lab 02"
... ])
>>> assignments.group_by(lambda s: s.split('-')[0].strip())
{'homework 01': Assignments(names=['homework 01', 'homework 01 - programming']),
 'homework 02': Assignments(names=['homework 02']),
 'homework 03': Assignments(names=['homework 03', 'homework 03 - programming']),
 'lab 01': Assignments(names=['lab 01']),
 'lab 02': Assignments(names=['lab 02'])}

See also

Gradebook.combine_assignment_parts(), Gradebook.combine_assignment_versions()

group_by_splitting_on(separator: str) dict[str, Assignments]

Group the assignments by splitting on a separator.

This is a convenience method which is equivalent to calling group_by() with a function that splits on the given separator, strips whitespace from the resulting strings, and returns the first part.

Parameters:

separator (str) – The separator to split on.

Returns:

A dictionary mapping keys to collections of assignments.

Return type:

dict[str, Assignments]

Example

>>> assignments = gradelib.Assignments([
... "homework 01", "homework 01 - programming", "homework 02",
... "homework 03", "homework 03 - programming", "lab 01", "lab 02"
... ])
>>> assignments.group_by_splitting_on('-')
{'homework 01': Assignments(names=['homework 01', 'homework 01 - programming']),
 'homework 02': Assignments(names=['homework 02']),
 'homework 03': Assignments(names=['homework 03', 'homework 03 - programming']),
 'lab 01': Assignments(names=['lab 01']),
 'lab 02': Assignments(names=['lab 02'])}

See also

Gradebook.combine_assignment_parts(), Gradebook.combine_assignment_versions()

not_containing(substring: str) Assignments

Return only those assignments not containing the substring.

Parameters:

substring (str) – The substring to search for.

Returns:

Only those assignments not containing the substring.

Return type:

Assignments

starting_with(prefix: str) Assignments

Return only those assignments starting with the prefix.

Parameters:

prefix (str) – The prefix to search for.

Returns:

Only those assignments starting with the prefix.

Return type:

Assignments