-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposting_list.py
More file actions
35 lines (28 loc) · 872 Bytes
/
posting_list.py
File metadata and controls
35 lines (28 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# The Node class acts as a node for each word,
# by storing the pageId of the word.
class Node:
def __init__(self, pageId=None):
self.pageId = pageId
self.nextval = None
class SlinkedList:
def __init__(self, head=None):
self.head = head
# to print the posting list
def __str__(self):
# defining a blank res variable
res = " "
# initializing ptr to head
ptr = self.head
ptr = ptr.nextval
# traversing and adding it to res
while ptr:
res += str(ptr.pageId) + ", "
ptr = ptr.nextval
# removing trailing commas
res = res.strip(", ")
# chen checking if
# anything is present in res or not
if len(res):
return "[" + res + "]"
else:
return "[]"