❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

Python Task – Tuple

2 August 2024 at 03:42
  1. Create a tuple containing the names of three fruits. Print the tuple and its type.
  2. Given a tuple t = ("apple", "banana", "cherry"), access and print the second element.
  3. Unpack the tuple t = (1, 2, 3) into variables a, b, and c, and print the variables.
  4. Concatenate two tuples t1 = (1, 2) and t2 = (3, 4) and print the result.
  5. Create a tuple t = ("repeat",) and repeat it three times. Print the resulting tuple.
  6. Given a tuple t = (1, 2, 3, 2, 2, 4), count the number of times the number 2 appears.
  7. Given a tuple t = ("a", "b", "c", "d"), find the index of the element "c".
  8. Check if the element 5 is present in the tuple t = (1, 2, 3, 4)
  9. Find and print the length of the tuple t = ("one", "two", "three").
  10. Slice the tuple t = (0, 1, 2, 3, 4, 5) to obtain a sub-tuple containing only the elements from index 2 to 4.
  11. Create a nested tuple representing a 2D point (x, y) = ((1, 2), (3, 4)). Access and print the second coordinate of the second point.
  12. Try to change the value of the first element in the tuple t = (1, 2, 3) and observe what happens.
  13. Convert a list l = [1, 2, 3] to a tuple and print the result. Then convert a tuple t = (4, 5, 6) to a list and print the result.
  14. Create a tuple with a single item 5 and verify its type is a tuple.
  15. Iterate over the tuple t = ("ParottaSalna", "is", "good") and print each element.
  16. Convert the string "hello" into a tuple of characters.
  17. Convert a dictionary d = {"one": 1, "two": 2} into a tuple of its items.
  18. Write a function that takes a tuple of numbers and returns the sum of the numbers.
  19. Use tuples as keys in a dictionary to represent points on a grid. For example, grid = {(0, 0): "origin", (1, 2): "point A"}.

Task – The Delivery MAN – Python List

30 July 2024 at 16:40
  1. Create a list of five delivery items and print the third item in the list. eg: [β€œNotebook”, β€œPencil”, β€œEraser”, β€œRuler”, β€œMarker”]
  2. A new delivery item β€œGlue Stick” needs to be added to the list. Add it to the end of the list and print the updated list.
  3. Insert β€œHighlighter” between the second and third items and print the updated list.
  4. One delivery was canceled. Remove β€œRuler” from the list and print the updated list.
  5. The delivery man needs to deliver only the first three items. Print a sublist containing only these items.
  6. The delivery man has finished his deliveries. Convert all item names to uppercase using a list comprehension and print the new list.
  7. Check if β€œMarker” is still in the list and print a message indicating whether it is found.
  8. Print the number of delivery items in the list.
  9. Sort the list of items in alphabetical order and print the sorted list.
  10. The delivery man decides to reverse the order of his deliveries. Reverse the list and print it.
  11. Create a list where each item is a list containing a delivery item and its delivery time. Print the first item and its time.
  12. Count how many times β€œRuler” appears in the list and print the count.
  13. Find the index of β€œPencil” in the list and print it.
  14. Extend the list items with another list of new delivery items and print the updated list.
  15. Clear the list of all delivery items and print the list.
  16. Create a list with the item β€œNotebook” repeated three times and print the list.
  17. Using a nested list comprehension, create a list of lists where each sublist contains an item and its length, then print the new list.
  18. Filter the list to include only items that contain the letter β€œe” and print the filtered list.
  19. Remove duplicate items from the list and print the list of unique items.

❌
❌