Common¶
This is a module containing common functions shared among the different solutions. While we tried to make solutions as stand-alone as possible, we could not help but encapsulate a couple of patterns to help readability.
Provide common functionality shared among all the solutions.
Classes:
|
Represent a sequence of text lines. |
Functions:
|
Iterate over |
- class Lines(lines: Sequence[str])[source]¶
Represent a sequence of text lines.
Methods:
__new__
(cls, lines)Ensure the properties on the
lines
.__add__
(other)Concatenate two list of lines.
Get the line(s) at the given index.
__len__
()Return the number of the lines.
__iter__
()Iterate over the lines.
- static __new__(cls, lines: Sequence[str]) Lines [source]¶
Ensure the properties on the
lines
.Please make sure that you transfer the “ownership” immediately to Lines and don’t modify the original list of strings any more:
## # OK ## lines = Lines(some_text.splitlines()) ## # Not OK ## some_lines = some_text.splitlines() lines = Lines(some_lines) # ... do something assuming ``lines`` is immutable ... some_lines[0] = "This will break \n your logic" # ERROR! lines[0] now contains a new-line which is unexpected!
- Requires
all('n' not in line and 'r' not in line for line in lines)