Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% 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.

Uploaded by

arif895178
Copyright
© © All Rights Reserved
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% 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.

Uploaded by

arif895178
Copyright
© © All Rights Reserved
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
You are on page 1/ 1

import collections

def collectionfunc(text1, dictionary1, key1, val1, deduct, list1):


# 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)

You might also like