Mujeeb urpxt
Posted Answers
Answer
- Security manager.
- Forensic accountant.
- Police sergeant.
- Judge.
- Forensic analyst.
- Lawyer.
- Detective.
- Border patrol agent.
Answer is posted for the following question.
Answer
1
# Insert dictionary item into a dictionary at specified position: 2
def insert_item(dic, item={}, pos=None):3
"""4
Insert a key, value pair into an ordered dictionary.5
Insert before the specified position.6
"""7
from collections import OrderedDict8
d = OrderedDict()9
# abort early if not a dictionary:10
if not item or not isinstance(item, dict):11
print('Aborting. Argument item must be a dictionary.')12
return dic13
# insert anywhere if argument pos not given: 14
if not pos:15
dic.update(item)16
return dic17
for item_k, item_v in item.items():18
for k, v in dic.items():19
# insert key at stated position:20
if k == pos:21
d[item_k] = item_v22
d[k] = v23
return d24
25
d = {'A':'letter A', 'C': 'letter C'}26
insert_item(['A', 'C'], item={'B'})27
## Aborting. Argument item must be a dictionary.28
29
insert_item(d, item={'B': 'letter B'})30
## {'A': 'letter A', 'C': 'letter C', 'B': 'letter B'}31
32
insert_item(d, pos='C', item={'B': 'letter B'})33
# OrderedDict([('A', 'letter A'), ('B', 'letter B'), ('C', 'letter C')])Source: Code Grepper
Answer is posted for the following question.
How to python 3.7 insert at place in dict (Python Programing Language)