# create a dictionary with key = keyname

 

'''

keyname first

keyword1 1.1

keyword2 1.2

keyword3 1.3

keyname second

keyword1 2.1

keyword2 2.2

keyword3 2.3

keyname third

keyword1 3.1

keyword2 3.2

keyword3 3.3

'''

 

fn = r'H:\TEMP\temsys\keyword.txt'

 

data = open(fn).read()

dataLst = [i.strip() for i in data.split('keyname') if i != '']

dd = {}

for item in dataLst:

    itemLst = item.split('\n')

    dd[itemLst[0]] = dict(zip([i.split()[0] for i in itemLst[1:]], [j.split()[1] for j in itemLst[1:]]))

 

for key in dd:

    print '%s = %s' % (key, dd[key])

 

'''

>>> second = {'keyword3': '2.3', 'keyword2': '2.2', 'keyword1': '2.1'}

third = {'keyword3': '3.3', 'keyword2': '3.2', 'keyword1': '3.1'}

first = {'keyword3': '1.3', 'keyword2': '1.2', 'keyword1': '1.1'}

>>>

'''