I would like to have two lists: one with the name of the fruit and another with the colors.
lista = ['banana [amarela]\n', 'uva [vinho]\n', 'laranja [laranjado]\n', 'kiwi [verde]\n', 'framboesa [vermelho]\n', 'coco [marrom]\n']
lines = lista.split(" ")
fruits = []
colors = []
for line in lines:
fruits.append(line[0])
#colors.append(line[1]) #IndexError: string index out of range
print(fruits)
#print(colors) #IndexError: string index out of range
Script output:
['' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' a ', a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'a', 'a', 'a', 'a', 'n', 'j', 'a', '', '' '' lololol, lolololol, lolololol, lololololol, lololololol, lololololol, lololololol, lololololol, lololololol, lololololol, lololololol, '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' 'e', '' '', '', '', '', '', '', '', '', '', '', '', '', '', '' ' ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee h ',' o ',' '' '' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' ]
Desired output:
fruits = ['banana', 'grape', 'orange', 'kiwi', 'raspberry', 'coconut']
colors = ['yellow', 'wine', 'orange', 'green', 'red', 'brown']