Ejemplo n.º 1
0
 def test_table_insert(self):
     table = Table(headers=['python', 'rules'])
     table.extend([[1, 2], [3, 4], [5, 6], [7, 8], [1, 2]])
     table.insert(0, [4, 2])
     table.insert(1, {'python': 9, 'rules': 9})
     self.assertEquals(table[0], [4, 2])
     self.assertEquals(table[1], [9, 9])
     self.assertEquals(len(table), 7)
Ejemplo n.º 2
0
 def test_table_insert(self):
     table = Table(headers=["python", "rules"])
     table.extend([[1, 2], [3, 4], [5, 6], [7, 8], [1, 2]])
     table.insert(0, [4, 2])
     table.insert(1, {"python": 9, "rules": 9})
     self.assertEquals(table[0], [4, 2])
     self.assertEquals(table[1], [9, 9])
     self.assertEquals(len(table), 7)
Ejemplo n.º 3
0
table = Table(headers=["City", "State", "Country"])
table.append(["Três Rios", "Rio de Janeiro", "Brazil"])
table.append(["Niterói", "Rio de Janeiro", "Brazil"])
table.append(["Rio de Janeiro", "Rio de Janeiro", "Brazil"])
table.append(["Porto Alegre", "Rio Grande do Sul", "Brazil"])
table.append(["São Paulo", "São Paulo", "Brazil"])

print "First 3 rows:"
for row in table[:3]:  # Slicing
    print row

# Change the two last rows:
table[-2:] = [["Junín", "Buenos Aires", "Argentina"], ["Ciudad del Este", "Alto Paraná", "Paraguay"]]
# Insert a row in the first position, using dict notation:
table.insert(0, {"City": "La Paz", "State": "La Paz", "Country": "Bolivia"})
print "New table:"
print table
print

table.reverse()
print "And the table in the reversed order:"
print table
print

popped_row = table.pop()
rio = ["Rio de Janeiro", "Rio de Janeiro", "Brazil"]
table.append(rio)  # repeated row
number_of_rios = table.count(rio)
index_of_first_rio = table.index(rio)
table.remove(rio)  # remove the first occurrence of this row
Ejemplo n.º 4
0
table = Table(headers=['City', 'State', 'Country'])
table.append(['Três Rios', 'Rio de Janeiro', 'Brazil'])
table.append(['Niterói', 'Rio de Janeiro', 'Brazil'])
table.append(['Rio de Janeiro', 'Rio de Janeiro', 'Brazil'])
table.append(['Porto Alegre', 'Rio Grande do Sul', 'Brazil'])
table.append(['São Paulo', 'São Paulo', 'Brazil'])

print 'First 3 rows:'
for row in table[:3]:
    print row

#Change the two last rows:
table[-2:] = [['Junín', 'Buenos Aires', 'Argentina'],
              ['Ciudad del Este', 'Alto Paraná', 'Paraguay']]
#Insert a row in the first position, using dict notation:
table.insert(0, {'City': 'La Paz', 'State': 'La Paz', 'Country': 'Bolivia'})
print 'New table:'
print table
print

table.reverse()
print 'And the table in the reversed order:'
print table
print

popped_row = table.pop()
rio = ['Rio de Janeiro', 'Rio de Janeiro', 'Brazil']
table.append(rio) #repeated row
number_of_rios = table.count(rio)
index_of_first_rio = table.index(rio)
table.remove(rio) #remove the first occurrence of this row
Ejemplo n.º 5
0
table = Table(headers=['City', 'State', 'Country'])
table.append(['Três Rios', 'Rio de Janeiro', 'Brazil'])
table.append(['Niterói', 'Rio de Janeiro', 'Brazil'])
table.append(['Rio de Janeiro', 'Rio de Janeiro', 'Brazil'])
table.append(['Porto Alegre', 'Rio Grande do Sul', 'Brazil'])
table.append(['São Paulo', 'São Paulo', 'Brazil'])

print 'First 3 rows:'
for row in table[:3]:  # Slicing
    print row

#Change the two last rows:
table[-2:] = [['Junín', 'Buenos Aires', 'Argentina'],
              ['Ciudad del Este', 'Alto Paraná', 'Paraguay']]
#Insert a row in the first position, using dict notation:
table.insert(0, {'City': 'La Paz', 'State': 'La Paz', 'Country': 'Bolivia'})
print 'New table:'
print table
print

table.reverse()
print 'And the table in the reversed order:'
print table
print

popped_row = table.pop()
rio = ['Rio de Janeiro', 'Rio de Janeiro', 'Brazil']
table.append(rio)  #repeated row
number_of_rios = table.count(rio)
index_of_first_rio = table.index(rio)
table.remove(rio)  #remove the first occurrence of this row