ListCollection indexer

__getitem__(index)

Gets a list by index.

def __getitem__(self, index: int):
    ...
ParameterTypeDescription
indexint

Examples

Shows how to verify owner document properties of lists.

doc = aw.Document()
lists = doc.lists
self.assertEqual(doc, lists.document)
list = lists.add(list_template=aw.lists.ListTemplate.BULLET_DEFAULT)
self.assertEqual(doc, list.document)
print('Current list count: ' + str(lists.count))
print('Is the first document list: ' + str(lists[0].equals(list=list)))
print('ListId: ' + str(list.list_id))
print('List is the same by ListId: ' + str(lists.get_list_by_list_id(1).equals(list=list)))

Shows how to apply list formatting of an existing list to a collection of paragraphs.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)
builder.writeln('Paragraph 1')
builder.writeln('Paragraph 2')
builder.write('Paragraph 3')
paras = [node.as_paragraph() for node in doc.get_child_nodes(aw.NodeType.PARAGRAPH, True)]
self.assertEqual(0, len([p for p in paras if p.list_format.is_list_item]))
doc.lists.add(aw.lists.ListTemplate.NUMBER_DEFAULT)
list = doc.lists[0]
for paragraph in paras:
    paragraph.list_format.list = list
    paragraph.list_format.list_level_number = 2
self.assertEqual(3, len([p for p in paras if p.list_format.is_list_item]))

See Also