Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jaime Collado
/
textflow
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a776068a
authored
Apr 05, 2022
by
Jaime Collado
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Class Sequence created
parent
1ba42b45
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
textflow/Sequence.py
textflow/Sequence.py
0 → 100644
View file @
a776068a
class
SequenceIterator
:
def
__init__
(
self
,
sequences
):
self
.
idx
=
0
self
.
data
=
sequences
def
__iter__
(
self
):
return
self
def
__next__
(
self
):
self
.
idx
+=
1
try
:
return
self
.
data
[
self
.
idx
-
1
]
except
IndexError
:
self
.
idx
=
0
raise
StopIteration
class
Sequence
:
def
__init__
(
self
,
id
,
sequences
):
self
.
id
=
id
self
.
sequences
=
sequences
def
__str__
(
self
):
return
f
"id: {self.id}, sequences: {self.sequences}"
def
__repr__
(
self
):
values
=
", "
.
join
([
sequence
.
__repr__
()
for
sequence
in
self
.
sequences
])
return
f
"Sequence({values})"
def
__len__
(
self
):
return
len
(
self
.
sequences
)
def
__iter__
(
self
):
return
SequenceIterator
(
self
.
sequences
)
def
__getitem__
(
self
,
i
):
if
isinstance
(
i
,
str
):
return
"Str indexing is not supported yet"
# TODO
elif
isinstance
(
i
,
int
):
if
i
<
0
:
i
=
len
(
self
.
sequences
)
+
i
if
i
>=
len
(
self
.
sequences
):
raise
IndexError
(
"Sequence index out of range"
)
else
:
return
self
.
sequences
[
i
]
else
:
invalid_type
=
type
(
i
)
raise
TypeError
(
"LockableList indices must be integers or slices, not {}"
.
format
(
invalid_type
.
__name__
)
)
def
get_depth
(
self
):
pass
# TODO
def
filter
(
self
,
level
,
criteria
):
pass
# TODO
# TODO: Move these tests to the ./tests folder
if
__name__
==
"__main__"
:
seq
=
Sequence
(
1
,
[
"doc1"
,
3
,
Sequence
(
4
,
[
2
])])
print
(
seq
)
print
(
seq
[
2
])
print
(
seq
[
"a"
])
for
s
in
seq
:
print
(
s
)
print
(
seq
[
20
])
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment