The output of my code makes a list in a column.
Code:
path = '/home/allan/Área de trabalho/adjetivos.txt'
i = 0
lista = []
conta = 1
with open (path) as file_obj:
ler = file_obj.readlines()
for le in ler:
#print(le.rstrip())
lista.append(le)
for i in lista:
tam = len(lista)
#print(tam)
if i == lista[0]:
print("1 ano: Bodas de "+str(i.title().rstrip()))
elif i != lista[0]:
conta = 1 + conta
print(str(conta)+" anos: Bodas de "+i.title().rstrip())
Current output:
1 ano: Bodas de Ágata
2 anos: Bodas de Água-Marinha
3 anos: Bodas de Âmbar
4 anos: Bodas de Alabastro
5 anos: Bodas de Alexandrita
6 anos: Bodas de Amazônia
7 anos: Bodas de Ametista
8 anos: Bodas de Andaluzite
9 anos: Bodas de Aventurina
10 anos: Bodas de Axinite
...
... This is how it continues
I would like to "break the text", that the list would continue alongside as in the image:
HowcanIdoit?
fortextointextos:print(max(len(texto)))
WhycannotIhavethesameeffectofcountingthecharactersasyoudidusinglistcomp?Myinterpretationseeingthecodeworkinginpythontutoris2listitemsform1,Eg:"coffee", "sugar" - > "sugar coffee". It sounds magical, how can he include himself?
Here:
Is this how it happens? See below:
escritas[pos % linhas_coluna]
would look like this:
...
[3 % 25]
[4 % 25]
[5 % 25]
...
So I would get the 3
and assign it to anos: Bodas de Âmbar (espaço de 25)
texto.ljust(tamanho, ' ')
would be:
anos: Bodas de Âmbar (espaço de 25)
, right?
I can not see this text going right, just to ljust (left) thus forming a single column!
Remembering: The program is working perfectly fine, but I do not reach the logic itself. How can he split into two if everything goes left ??