[Type C]Q4. Write a python program directed for the Linear Lists in the problem statement.

What are Linear Lists?

A list is a collection that is ordered and changeable. In Python, lists are written with square brackets.

Lists are just like dynamic sized arrays, declared in other languages. Lists do not need to be homogeneous always, which makes it a most powerful tool in Python.

A single list may contain DataTypes like Integers, Strings, as well as Objects.

Lists are mutable, and hence, they can be altered even after their creation.

List Operations: Some common functions of lists are

Append()Add an element to the end of the list
Extend()Add all elements of a list to the another list
Insert()Insert an item at the defined index
Remove()Removes an item from the list
Pop()Removes and returns an element at the given index
Clear()Removes all items from the list
Index()Returns the index of the first matched item
Count()Returns the count of number of items passed as an argument
Sort()Sort items in a list in ascending order
Table of most used functions of list.

Problem: Take two lists and find all list elements which are common to both the lists.

Program code:

Output:

{1, 2, 3, 4, 5, 8, 13}

In the above code snippet basic functions of list are demonstrated.

To view all the lessons in chapter 9: http://computertutor.in/class-12-computer-science/chapter-9/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page