Yahoo India Web Search

Search results

  1. May 9, 2023 · Python Tuple [ 33 exercises with solution] A tuple is a container which holds a series of comma-separated values (items or elements) between parentheses such as an (x, y) co-ordinate. Tuples are like lists, except they are immutable (i.e. you cannot change its content once created) and can hold mix data types.

  2. Nov 7, 2023 · Python Exercises, Practice and Solution: Write a Python program to find repeated items in a tuple.

  3. Nov 7, 2023 · Python tuple: Exercise-13 with Solution. Write a Python program to slice a tuple. Visual Presentation: Sample Solution: Python Code: # Create a tuple containing a sequence of numbers tuplex = (2, 4, 3, 5, 4, 6, 7, 8, 6, 1) # Use tuple slicing (tuple[start:stop]) to extract a portion of the tuple.

  4. Nov 7, 2023 · Write a Python program to create a tuple. Sample Solution: Python Code: # Create an empty tuple and assign it to the variable 'x' x = () # Print the contents of the 'x' tuple, which is empty print (x) # Create an empty tuple using the tuple () constructor and assign it to the variable 'tuplex' tuplex = tuple () # Print the contents of the ...

  5. Nov 29, 2023 · subject_marks.sort (key=lambda x: x [1]): Sorts the list of tuples (subject_marks) based on the second element of each tuple (i.e., the marks). It uses a lambda function as the sorting key, which extracts the second element (x [1]) for sorting purposes.

  6. Nov 7, 2023 · Python Exercises, Practice and Solution: Write a Python program to add an item to a tuple.

  7. Python tuple: Exercise-21 with Solution. Write a Python program to replace the last value of tuples in a list. Sample Solution: Python Code: # Create a list of tuples, where each tuple contains three numbers. l = [(10, 20, 40), (40, 50, 60), (70, 80, 90)] # Use a list comprehension to iterate through each tuple 't' in the list 'l'.

  8. Nov 7, 2023 · Write a Python program to reverse a tuple. Visual Presentation: Sample Solution: Python Code: # Create a tuple containing a single string x = ("w3resource") # Reverse the characters in the string by using the 'reversed' function, # and then convert the reversed object back into a tuple and print it. y = reversed (x) print (tuple (y)) # ...

  9. May 9, 2023 · Write a Python program to convert a given list of tuples to a list of strings. Original list of tuples: [('red', 'green'), ('black', 'white'), ('orange', 'pink')]

  10. Nov 7, 2023 · Write a Python program to convert a tuple to a dictionary. # Create a tuple containing nested tuples, where each inner tuple consists of two elements. tuplex = ( (2, "w"), (3, "r")) # Create a dictionary by using a generator expression to swap the elements of each inner tuple.