Let's say I have two lists like this that must be represented as pairs:
cities = ['San Francisco', 'New York', 'Seattle', 'Portland', ]
states = ['CA', 'NY', 'WA', 'OR']
And I have a function like this:
def list(page):
return "{0} -> {1} \n {2} -> {3} \n {4} -> {5} \n {6} -> {7}".format(keys[0], values[0], keys[1], values[1], keys[2], values[2], keys[3], values[3])
I want to be able to use an integer (here, page
) to index these pairs display them three at a time. So let's say I have ten pairs of cities and states, 1
it would display the first three, 2
the second three, etc.
Pseudo-ly, I imagine it would look like this:
def list(page):
for page < 2:
return first triplet
for page < 3:
return second triplet
# etc.
But I think there could be a better way, and I'm wondering what that might look like.