Skip to content
Ankita Wankhede edited this page Jul 5, 2017 · 2 revisions

Case1:Dictionaries a.What we should do for having a dictionary that has order (dictionaries do not have order)

Answer:
The order is not arbitrary, but depends on the insertion and deletion history of the dictionary or set, as well as on the specific Python implementation. For 'dictionary', you can also read 'set'; sets are implemented as dictionaries with just keys and no values.

Python use hash table for storing the dictionaries, so there is no order in dictionaries or other iterable objects that use hash table.The only thing about dictionary ordering you can rely on is that the order will remain the same if there are no modifications to the dictionary; e.g., iterating over a dictionary twice without modifying it will result in the same sequence of keys. However, though the order of Python dictionaries is deterministic, it can be influenced by factors such as the order of insertions and removals, so equal dictionaries can end up with different orderings:

{1: 0, 2: 0}, {2: 0, 1: 0} ({1: 0, 2: 0}, {1: 0, 2: 0}) {1: 0, 9: 0}, {9: 0, 1: 0} ({1: 0, 9: 0}, {9: 0, 1: 0})

b.Write a function to replace dictionary values with their sum.Use a list which contains three dictionaries. For example [{},{},{}]. Then sum the values of the dictionaries if they are integer

c.Write a Python program toget a comma separated sequence of words then the output should be sorted in comma separated manner.Ex:Input: music, film, pythonOutput: film, music, pythond.

d.Write a Python program to create a symmetric difference.

Clone this wiki locally