tabela = [
['A-B', 22, 0.045, 0.1, 0.005],
['A-C', 50, 0.020, 0.1, 0.002],
['A-D', 48, 0.021, 0.1, 0.002],
['A-E', 29, 0.034, 0.1, 0.003]
]
# Método usando for.
nova_lista_for = []
for sub_lista in tabela:
nova_lista_for.append(sub_lista[1])
print('Resultado usando for: ', nova_lista_for)
# Método usando list comprehensions.
nova_lista_comprehensions = [sub_lista[1] for sub_lista in tabela]
print('Resultado usando list comprehensions: ', nova_lista_comprehensions)
# Soma os valores retornados usando list comprehensions.
soma_campos = sum([sub_lista[1] for sub_lista in tabela])
print('Soma dos valores retornados usando list comprehensions: ', soma_campos)
dGFiZWxhID0gWwogICAgWydBLUInLCAyMiwgMC4wNDUsIDAuMSwgMC4wMDVdLAogICAgWydBLUMnLCA1MCwgMC4wMjAsIDAuMSwgMC4wMDJdLAogICAgWydBLUQnLCA0OCwgMC4wMjEsIDAuMSwgMC4wMDJdLAogICAgWydBLUUnLCAyOSwgMC4wMzQsIDAuMSwgMC4wMDNdCl0KCiMgTcOpdG9kbyB1c2FuZG8gZm9yLgpub3ZhX2xpc3RhX2ZvciA9IFtdCmZvciBzdWJfbGlzdGEgaW4gdGFiZWxhOgogICAgbm92YV9saXN0YV9mb3IuYXBwZW5kKHN1Yl9saXN0YVsxXSkKcHJpbnQoJ1Jlc3VsdGFkbyB1c2FuZG8gZm9yOiAnLCBub3ZhX2xpc3RhX2ZvcikKCiMgTcOpdG9kbyB1c2FuZG8gbGlzdCBjb21wcmVoZW5zaW9ucy4Kbm92YV9saXN0YV9jb21wcmVoZW5zaW9ucyA9IFtzdWJfbGlzdGFbMV0gZm9yIHN1Yl9saXN0YSBpbiB0YWJlbGFdCnByaW50KCdSZXN1bHRhZG8gdXNhbmRvIGxpc3QgY29tcHJlaGVuc2lvbnM6ICcsIG5vdmFfbGlzdGFfY29tcHJlaGVuc2lvbnMpCgojIFNvbWEgb3MgdmFsb3JlcyByZXRvcm5hZG9zIHVzYW5kbyBsaXN0IGNvbXByZWhlbnNpb25zLgpzb21hX2NhbXBvcyA9IHN1bShbc3ViX2xpc3RhWzFdIGZvciBzdWJfbGlzdGEgaW4gdGFiZWxhXSkKcHJpbnQoJ1NvbWEgZG9zIHZhbG9yZXMgcmV0b3JuYWRvcyB1c2FuZG8gbGlzdCBjb21wcmVoZW5zaW9uczogJywgc29tYV9jYW1wb3Mp
('Resultado usando for: ', [22, 50, 48, 29])
('Resultado usando list comprehensions: ', [22, 50, 48, 29])
('Soma dos valores retornados usando list comprehensions: ', 149)