0% found this document useful (0 votes)
7 views4 pages

Tuples

Uploaded by

Dinesh Babu
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)
7 views4 pages

Tuples

Uploaded by

Dinesh Babu
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/ 4

Problem 1: Tuple Comparison

Given two tuples, t1 and t2, compare them and determine if they are equal or which one is greater.

python

Copy code

# Example

t1 = (1, 2, 3)

t2 = (1, 2, 4)

# Your code here to compare t1 and t2

# Output: t1 < t2

Problem 2: Convert Tuple to List

You have a tuple t containing several elements. Convert it to a list and modify one of the elements.
Then, convert it back to a tuple.

python

Copy code

# Example

t = (1, 2, 3, 4)

# Your code here to convert t to a list, modify an element, and convert back to a tuple

# Output: (1, 2, 99, 4)

Problem 3: Find Maximum and Minimum

Given a tuple t of integers, find the maximum and minimum values without using built-in functions.

python

Copy code

# Example

t = (5, 2, 9, 1, 5, 6)

# Your code here to find the maximum and minimum values

# Output: Maximum: 9, Minimum: 1


Problem 4: Count Occurrences of an Element

You are given a tuple t and a specific value. Count how many times that value appears in the tuple.

python

Copy code

# Example

t = ('a', 'b', 'c', 'a', 'd', 'a')

# Your code here to count occurrences of 'a' in t

# Output: 3

Problem 5: Create a Tuple of Even Numbers

Given a list of integers, create a tuple containing only the even numbers from that list.

Problem 1: Swap Elements

You are given a tuple t containing two elements. Swap the elements of the tuple.

python

Copy code

# Example

t = (1, 2)

# Your code here to swap the elements of t

# Output: (2, 1)

Problem 2: Tuple Unpacking

Given a tuple data containing the name, age, and city of a person, unpack the values into separate
variables.

python

Copy code

# Example

data = ("Alice", 30, "New York")


# Your code here to unpack data into name, age, city

# Output: name = "Alice", age = 30, city = "New York"

Problem 3: Count Occurrences

You have a tuple t with several elements. Count how many times a specific element appears in the
tuple.

python

Copy code

# Example

t = (1, 2, 3, 1, 4, 1, 5)

element = 1

# Your code here to count occurrences of element in t

# Output: 3

Problem 4: Find Index of Element

Given a tuple t and a specific element, find the index of that element in the tuple.

python

Copy code

# Example

t = ('a', 'b', 'c', 'd')

element = 'c'

# Your code here to find the index of element in t

# Output: 2

Problem 5: Concatenate Tuples

You have two tuples, t1 and t2. Concatenate these two tuples into a new tuple.

python

Copy code
# Example

t1 = (1, 2, 3)

t2 = (4, 5)

# Your code here to concatenate t1 and t2

# Output: (1, 2, 3, 4, 5)

You might also like