Python Collection Module

Python Programming Training Certification

Flexible Hours

100 Assignments

Instructor Led online Training

50 LMS Access

24X7 Support

100% Skill Level

Enquire Now

4.9 out of 1000+ Ratings
Best Python Institute for Learning Python Course & Training, Live Project Training in Python with Django, Data Science and AI, Interview Assistance, Expert Coaching Trainers. Python Certification & Interview Assistance! Get free demo now!

Course Overview

Python is one of the world’s top programming languages used today and Python training has become the most popular training across individuals. Training Basket’s Python Training & Certification course covers basic and advanced Python concepts and how to apply them in real-world applications.Python is a flexible and powerful open-source language that is easy to learn and consists of powerful libraries for data analysis and manipulation. Our Python training course content is curated by experts as per the standard Industry curriculum. The curriculum, coding challenges and real-life problems cover data operations in Python, strings, conditional statements, error handling, shell scripting, web scraping and the commonly used Python web framework Django. Take this Python training and certification course and become job-ready now.

Python Collection Module

The Python collection module is defined as a container that is used to store collections of data, for example – list, dict, set, and tuple, etc. It was introduced to improve the functionalities of the built-in collection containers.

Python collection module was first introduced in its 2.4 release.

There are different types of collection modules which are as follows:

namedtuple()

The Python namedtuple() function returns a tuple-like object with names for each position in the tuple. It was used to eliminate the problem of remembering the index of each field of a tuple object in ordinary tuples.

Examples

  • pranshu = (‘James’, 24, ‘M’)
    print(pranshu)

Output:

  • (‘James’, 24, ‘M’)

OrderedDict()

The Python OrderedDict() is similar to a dictionary object where keys maintain the order of insertion. If we try to insert key again, the previous value will be overwritten for that key.

Example

  • import collections
    d1=collections.OrderedDict()
    d1[‘A’]=10
    d1[‘C’]=12
    d1[‘B’]=11
    d1[‘D’]=13

    for k,v in d1.items():
    print (k,v)

Output:

  • A 10
    C 12
    B 11
    D 13

defaultdict()

The Python defaultdict() is defined as a dictionary-like object. It is a subclass of the built-in dict class. It provides all methods provided by dictionary but takes the first argument as a default data type.

Example

  • from collections import defaultdict
    number = defaultdict(int)
    number[‘one’] = 1
    number[‘two’] = 2
    print(number[‘three’])

Output:

  • 0

Counter()

The Python Counter is a subclass of dictionary object which helps to count hashable objects.

Example

  • from collections import Counter
    c = Counter()
    list = [1,2,3,4,5,7,8,5,9,6,10]
    Counter(list)
    Counter({1:5,2:4})
    list = [1,2,4,7,5,1,6,7,6,9,1]
    c = Counter(list)
    print(c[1])

Output:

  • 3

deque()

The Python deque() is a double-ended queue which allows us to add and remove elements from both the ends.

Example

  • from collections import deque
    list = [“x”,”y”,”z”]
    deq = deque(list)
    print(deq)

Output:

  • deque([‘x’, ‘y’, ‘z’])

Chainmap Objects

A chainmap class is used to groups multiple dictionary together to create a single list. The linked dictionary stores in the list and it is public and can be accessed by the map attribute. Consider the following example.

Example

  • from collections import ChainMap
    baseline = {‘Name’: ‘Peter’, ‘Age’: ’14’}
    adjustments = {‘Age’: ’14’, ‘Roll_no’: ‘0012’}
    print(list(ChainMap(adjustments, baseline)))

Output:

  • [‘Name’, ‘Age’, ‘Roll_no’ ]

UserDict Objects

The UserDict behaves as a wrapper around the dictionary objects. The dictionary can be accessed as an attribute by using the UserDict object. It provides the easiness to work with the dictionary.

It provides the following attribute.

data – A real dictionary used to store the contents of the UserDict class.

UserList Objects

The UserList behaves as a wrapper class around the list-objects. It is useful when we want to add new functionality to the lists. It provides the easiness to work with the dictionary.

It provides the following attribute.

data – A real list is used to store the contents of the User class.

UserString Objects

The UserList behaves as a wrapper class around the list objects. The dictionary can be accessed as an attribute by using the UserString object. It provides the easiness to work with the dictionary.

It provides the following attribute.

data – A real str object is used to store the contents of the UserString class.

Recently Trained Students

Jessica Biel

– Infosys

My instructor had sound Knowledge and used to puts a lot of effort that made the course as simple and easy as possible. I was aiming for with the help of the ZebLearn Online training imparted to me by this organization.

Richard Harris

– ITC

I got my training from Zeblearn in the Python Certification Training, I would like to say that say he is one of the best trainers. He has not even trained me but also motivated me to explore more and the way he executed the project, in the end, was mind-blowing.


Candidate’s Journey During Our Training Program

Card image cap

Expert’s Advice & Selection of Module

Choosing the right type of module for the training is half the battle & Our Team of experts will help & guide you.

Card image cap

Get Trained

Get Trained & Learn End to End Implementation from our Expert Trainer who are working on the same domain.

Card image cap

Work on Projects

We Do make our student’s work on multiple case studies , scenario based tasks & projects in order to provide real-time exposure to them.

Card image cap

Placements

We have a dedicated placement cell in order to provide placement assistance & relevant interviews to our candididates till selection

Placement Partner

×

Leave your details

×

Download Course Content



wop;[\]