The dictionary in python associates key with values and written with in {} curly braces as shown below.

l={‘punjab’:’chandigarh’,’haryana’:’chandigarh’,’himachal’:’shimla’,’up’:’lukhnow’}

Keys: states names are keys (punjab, haryana, himachal, up)

Values: Each key has values assigned to it in this case chandigarh,shimla,lukhnow are the values.

how to write dictionary in python
Dictionary in Python

Any values associated with key can be checked by typing dictionary [Key].The keys and values are also checked by its function keys l.keys and values l.values as shown in image above.

Sets are writen with curley braces but without colons as shown in image below.

how to write sets in python
Sets in python

Even it had some value twice but it returned only unique values and eliminated duplicacy.

By SC

One thought on “Dictionary & Sets in Python”

Leave a Reply

Your email address will not be published. Required fields are marked *