0% found this document useful (0 votes)
97 views5 pages

03 - List, Tuple - Exercise

The document provides assignment instructions for a programming task involving lists and tuples in Python, including various questions and coding exercises. It emphasizes attempting all questions, joining mentoring sessions for support, and includes specific coding tasks such as creating lists, modifying tuples, and using list comprehension. Additionally, it contains descriptive questions that require explanations of Python concepts like the differences between lists and tuples, and methods like append() and extend().

Uploaded by

bragha144
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views5 pages

03 - List, Tuple - Exercise

The document provides assignment instructions for a programming task involving lists and tuples in Python, including various questions and coding exercises. It emphasizes attempting all questions, joining mentoring sessions for support, and includes specific coding tasks such as creating lists, modifying tuples, and using list comprehension. Additionally, it contains descriptive questions that require explanations of Python concepts like the differences between lists and tuples, and methods like append() and extend().

Uploaded by

bragha144
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment Instructions

Hello Innominion,

• Try to attempt all the questions in every possible way.

• Some other topics are required to solve some questions. don't panic.

• Those questions can be answered after the topics are taught.

• Join Mentoring Session for the Support/Doubts Resolving with Our


Technical Mentors (2.00 PM - 6.00 PM Mon-Sat)

Happy Learning !!!

LIST
Question::Create a list of numbers

nums = [1,2,3,4]

[1, 2, 3, 4]

** Question: Remove number "3" in a list**

# Method 1

[1, 2, 4]

# Method 2

[1, 2, 4]

# Method 3

[1, 2, 4]

Question: :Insert number "1" in 0th position

• lst = [2,3,4]

[1, 2, 3, 4]

Question: Insert "two-and-half" in 2nd position


[1, 2, 'two-and-half', 3, 4]

Question: phrase = "Don't panic!"

• Convert above text into list


# CODE HERE

convert into list

['D', 'o', 'n', "'", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']

Question: Remove ** '** and ! in the list

['D', 'o', 'n', 't', ' ', 'p', 'a', 'n', 'i', 'c']

Question: Remove "p" , "a", "n","D" and extend at the last

# CODE HERE

['o', 'n', 't', ' ', 'i', 'c', 'p', 'a', 'n', 'D']

Question: Join the given list ['p', 'a', 'n', 'D', 'a']

# CODE HERE

'panDa'

Tuples
Question: Create a tuples for numbers 31,24,35,85 as nums

# CODE HERE
data type <class 'tuple'>
(31, 24, 35, 85)

Question: Remove number "35" in a tuple

Hint: Convert into list

# CODE HERE

(31, 24, 85)

Extent tuple (85,19)

# CODE HERE

(31, 24, 85, 85, 19)

Question: Write code to check whether an element ('i') exists within a tuple.

• tpl = ('i','n''n','0')
# CODE HERE

True

Question: Write a python code to replace/insert the value

• list = ['Hello',100,[],'innomatics']
# CODE HERE

['Hello', 100, [200], 'innomatics']

Question: Write a Python program to reverse a tuple.

# CODE HERE
tpl = ("Innomatics")

('s', 'c', 'i', 't', 'a', 'm', 'o', 'n', 'n', 'I')

tpl = (1,2,3)+(4,)
tpl
(1, 2, 3, 4)

Question: Write a Python program to add one more value at last postion of tuples in a list

• tpl = [(10, 20, 40), (40, 50, 60), (70, 80, 90)]
• hint- use for loop
# CODE HERE
tpl = [(10, 20, 40), (40, 50, 60), (70, 80, 90)]

[(10, 20, 40, 100), (40, 50, 60, 100), (70, 80, 90, 100)]

Question: Write a Python program to replace last value of tuples in a list

• tpl = [(10, 20, 40), (40, 50, 60), (70, 80, 90)]
• hint- use for loop
# CODE HERE
tpl = [(10, 20, 40), (40, 50, 60), (70, 80, 90)]

[(10, 20, 100), (40, 50, 100), (70, 80, 100)]

Question: If the following string is given as input to the program:


• '5 2 3 6 6 5'

FInd the secong higest value from that


# CODE HERE

5 2 4 6 2 2
second higest is : 5

Question: By using list comprehension, please write a program to print


the list after removing the 0th,4th,5th numbers in
[12,24,35,70,88,120,155].
# CODE HERE

[24, 35, 70, 155]

Question: With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to


print the first half values in one line and the last half values in one line.

(1, 2, 3, 4, 5) (6, 7, 8, 9, 10)


Question: Write a program to generate and print another tuple whose
values are even numbers in the given tuple (1,2,3,4,5,6,7,8,9,10)

(2, 4, 6, 8, 10)

Descriptive Questions

1. Explain the difference between list and tuple?


# Solution

2. Explain the difference between append() and extend() with examples


# Solution

3. Explain the difference between pop() and remove() with examples


# Solution

Innomatics Research Labs


www.innomatics.in

You might also like