Python Programing Lab (R16) EXERCISE - 6(a)

Python Programing Lab (R16)  EXERCISE - 6(a)

Aim:

Write a program combine_lists that combines these lists into a dictionary.

Description:

Python offers a range of compound data types often referred to as Sequences. List is one of the most frequently used and very versatile data type used in Python.

In Python Programming, a List is created by placing all the elements inside a square bracket [ ], separated by commas. It can have any number of items and they may be of different types.

Examples:

list1 = [10,20,30,40]

list2 = [“Ram”,19,87.81]

Similar to string indices, list indices starts at 0 and lists can be sliced, concatenated and so on..

Here, The task is to combine 2 lists into a dictionary. That means, One list elements will become the keys and another list elements will become the values in the resultant dictionary.

Program:

lists=list()
n=int(input("Enter no.of lists u want to combine"))
for i in range(0,n):
    a=input("Enter the value")
    lists.append(a)
for b in lists:
    print b
dic=dict([(digit,[]) for digit in lists[:]])
print(dic)

Output:


No comments

Web Development with PHP Course

  Course : Web Development with PHP The Importance Of PHP Web Development Website development is rapidly growing tool for business developme...