# -*- coding: utf-8 -*- from collections import defaultdict import pprint data = u""" Öğrenci Tüm okullar Lisans Önlisans Yüksek Lisans / Doktora İngilizce Hazırlık Öğretim Elemanı Tüm okullar Lisans Önlisans Yüksek Lisans / Doktora İngilizce Hazırlık """ result = defaultdict(list) current_key = None for line in data.splitlines(): if not line: continue # Filter out blank lines # If the line is not indented then it is a key # Save it and move on if not line[0].isspace(): current_key = line.strip() continue # Otherwise, add the value # (minus leading and trailing whitespace) # to our results result[current_key].append(line.strip()) pprint.pprint(dict(result))