Pokemon: Charmander
Tipo: Fuego
Habilidades:
Normales: Mar Llamas
Oculta: Poder Solar
Pokemon: Bulbasaur
Tipo: Planta
Habilidades:
Normales: Espesura
Oculta: Clorofila
Peso: 6.9 kg
Pokemon: Pikachu
Tipo: Electrico
Habilidades:
Normales: Estática
Oculta: Pararrayos
Peso: 6 kg
Código con base a la respuesta
#!/usr/bin/python3.6
import json
index_info = []
json_data = {"pokemones": []}
pokemones = []
types = []
weight = []
with open('pokemon.txt', 'r+') as f:
text = f.readlines()
for indice, line in enumerate(text):
if line.startswith('Pokemon'):
#print(line)
index_info.append(indice)
for inicio, fin in zip(index_info, index_info[1:]):
trozo = text[inicio:fin]
#print(trozo)
#procesar_pokemon(trozo)
for line in trozo:
if line.startswith('Pokemon'):
pokemon = line[9:len(line)].strip()
pokemones.append(pokemon)
if line.startswith(' Tipo'):
type = line[9:len(line)].strip()
types.append(type)
if line.startswith(' Peso'):
w = line[9:len(line)].strip()
weight.append(w)
print(index_info)
print(index_info[1:])
#print(pokemones)
#print(types)
#print(weight)
for i in range(len(pokemones)):
json_data["pokemones"].append({
"name": pokemones[i],
"type": types[i],
#"weight": weight[i]
})
print(json.dumps(json_data, indent=4, default=str))