The document contains a Python function that processes a given text to count word occurrences, updates a dictionary by deducting specified values, and organizes keys and values into a new dictionary. It also separates a list of numbers into even and odd categories. The function prints the results of these operations.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
6 views
Hands-On - Python - Collections
The document contains a Python function that processes a given text to count word occurrences, updates a dictionary by deducting specified values, and organizes keys and values into a new dictionary. It also separates a list of numbers into even and odd categories. The function prints the results of these operations.
# Write your code here dic=dict() sdic=dict() t=text1.split() for w in t: count=t.count(w) dic[w]=count od=collections.OrderedDict(sorted(dic.items())) for k, v in od.items(): sdic[k]=v print(sdic) for k, v in deduct.items(): dictionary1[k]=dictionary1.get(k,0)-v print(dictionary1) odic=dict() for i in range(len(key1)): odic[key1[i]]=val1[i] del odic[key1[1]] odic[key1[1]]=val1[1] print(odic) el=list() ol=list() for i in list1: if i%2==0: el.append(i) else: ol.append(i) eodic=dict() if len(ol)!=0: eodic['odd']=ol if len(el)!=0: eodic['even']=el print(eodic)