Aim:
Write a program combine_lists that combines these lists into a dictionary.
Program:
l1=[1,2,'cse',4,5] l2=['khit',7,'cse',9] l=l1+l2 d={} for i in range(len(l)): d[i]=l[i] print("The dictionary is------>",d)
Output:
The dictionary is------> {0: 1, 1: 2, 2: 'cse', 3: 4, 4: 5, 5: 'khit', 6: 7, 7: 'cse', 8: 9}
(or)
Program:
l=[1,'python',4,7] k=['cse',2,'guntur',8] m=[] m.extend(l); m.extend(k); print(m) d={1:l,2:k,'combine_list':m} print(d)
Output:
[1, 'python', 4, 7, 'cse', 2, 'guntur', 8] {1: [1, 'python', 4, 7], 2: ['cse', 2, 'guntur', 8], 'combine_list': [1, 'python', 4, 7, 'cse', 2, 'guntur', 8]}
(or)
Program:
l=[1,'python',4,7] k=['cse',2,'guntur',8] m=[] m.append(l); m.append(k); print(m) d={1:l,2:k,'combine_list':m} print(d)
Output:
[[1, 'python', 4, 7], ['cse', 2, 'guntur', 8]] {1: [1, 'python', 4, 7], 2: ['cse', 2, 'guntur', 8], 'combine_list': [[1, 'python', 4, 7], ['cse', 2, 'guntur', 8]]}