Python Code for Count Occurrences All item in Tuple and List in Tamil | #python_code #Tuple #List

preview_player
Показать описание
Join this channel to get access to perks:

In this video, I’ll show you

AIM:
This program is to count the occurrences of all items from a given list in a given tuple.
ALGORITHM:
1. Create a function called count_occurrences(tuple_data, list_data) to count occurrences.
2. Initialize a dictionary called occurrences_dict to store the count of each item from the list.
3. Loop through each item in the list_data:
a. For each item, initialize its count to 0 in the occurrences_dict.
4. Loop through each item in the tuple_data:
a. If the item is present in the occurrences_dict, increment its count by 1.
5. After counting all occurrences, sum up the counts of all items from the list_data
present in the occurrences_dict.
6. Return the total count.
TUPLE AND LIST:
In Python, tuple and list are two built-in data structures used for storing collections of
elements. Both are used to store multiple items in a single variable, but they have some
key differences:
Tuple:
1. A tuple is an ordered, immutable collection of elements.
2. Once created, the elements in a tuple cannot be changed, added, or removed.
3. Tuples are defined using parentheses () and can contain elements of different data
types.
4. Elements in a tuple are accessed using zero-based indexing (e.g.,
tuple_name[index]).
5. Tuples are generally used to store a fixed collection of items where the items are
not intended to be modified after creation.
Example: Python code
# Creating a tuple
my_tuple = (1, 'hello', 3.14, True)
# Accessing elements of the tuple
print(my_tuple[0]) # Output: 1
print(my_tuple[1]) # Output: 'hello'
List:
1. A list is an ordered, mutable collection of elements.
2. Lists can be modified after creation, i.e., elements can be added, removed, or
changed.
3. Lists are defined using square brackets [] and can contain elements of different
data types.
4. Elements in a list are accessed using zero-based indexing (e.g., list_name[index]).
5. Lists are commonly used when you need to work with a collection of items that
may change during the program's execution
Example: pythoncode
# Creating a list
my_list = [1, 2, 3, 4, 5]
# Accessing elements of the list
print(my_list[0]) # Output: 1
print(my_list[3]) # Output: 4
In summary, the main differences between tuples and lists are their mutability and the
syntax used to define them. Tuples are immutable and defined with parentheses, while
lists are mutable and defined with square brackets.

Enjoy!

Like

Share

Comment

Subscribe

#சங்கேமுழங்கு

Follow me:
******************************************************************
Instagram : Sanke_Muzangu
Twitter: @Sanke_Muzangu
*****************************************************************
Рекомендации по теме
welcome to shbcf.ru