Q:

Sorting dictionary elements from file with capitalization of first letter

Hi i am writing a program to read a dictionary from file and then it capital the first letter and sort it alphabetically
What i am trying is to convert dictionary into list. Then i have tried for loop but somehow it is not working
my file contains
banana:123
sweet:32
nutella:23

my code:
f = open("test.txt", "r")
lst=[]
for line in f.readlines():
    data,price = line.split(":")
    lst.append([data, (price)])
f.close()

now when i try for loop to get the index it gives me error 
for i in range(lst[0:len(lst)][0]):

it gives me error: 
TypeError: 'list' object cannot be interpreted as an integer

My question is getting confusing... The main thing i need to be done is that the first letter of each line becomes capital and they get sorted in file alphabetically. 
also please tell me what i am doing wrong in this for loop... I want index to start from [0] to the len[lst] 

A:

for the range issue just use 
for i in range(len(lst)):

you provide a list instead of an integer 
for the sorting use this 
from operator import itemgetter
f = open("test.txt", "r")
lst = []
for line in f.readlines():
    data, price = line.split(":")
    lst.append([data, (price)])
f.close()
lst = sorted(lst, key=itemgetter(1))
print map(lambda x: x[0] + ":" + x[1],  map(lambda x: [x[0].capitalize(), x[1]], lst))

       .....
       .....
 and write to the file 

