This page gives examples of how to use to iterate over the different Python collection types and how to access the objects stored in the collection. Each section contains Python code to create the data structure and an HTML template. Some examples show alternative ways of writing the template. = A list of strings = {{{ ctx.locals.strings = ['one', 'two', 'three', 'four', 'five'] }}} {{{
}}} = A list of objects = {{{ class Person: def __init__(self, first_name, last_name): self.first_name = first_name self.last_name = last_name people = [ Person('Graham', 'Chapman'), Person('John', 'Cleese'), Person('Terry', 'Gilliam'), Person('Eric', 'Idle'), Person('Terry', 'Jones'), Person('Michael', 'Palin')] ctx.locals.people = people }}} {{{ ,

}}} = A list of tuples = {{{ people = [ ('Graham', 'Chapman'), ('John', 'Cleese'), ('Terry', 'Gilliam'), ('Eric', 'Idle'), ('Terry', 'Jones'), ('Michael', 'Palin')] ctx.locals.people = people }}} {{{ ,

}}} = A list of dictionaries = {{{ people = [ {'first_name':'Graham', 'last_name':'Chapman'}, {'first_name':'John', 'last_name':'Cleese'}, {'first_name':'Terry', 'last_name':'Gilliam'}, {'first_name':'Eric', 'last_name':'Idle'}, {'first_name':'Terry', 'last_name':'Jones'}, {'first_name':'Michael', 'last_name':'Palin'}] ctx.locals.people = people }}} {{{ ,

}}} = A dictionary = {{{ english_numbers = {1:'one', 2:'two', 3:'three', 4:'four', 5:'five'} ctx.locals.number = english_numbers }}} {{{

Keys:


Values:


Keys and values:

:
}}}