PYTHON - SETS

 Sets:


Sets are unordered collections of unique elements.
They are defined using curly braces {} or the set() constructor.
Sets are useful for removing duplicates and performing set operations (union, intersection, difference, etc.).

In Python, a set is an unordered collection of unique elements. Sets are defined using curly braces {} or the set() constructor. Sets do not allow duplicate values, and they are primarily used for performing mathematical set operations like union, intersection, difference, and more. Here, I'll explain in detail about sets and their operations in Python.

Example:

my_set = {1, 2, 3, 4, 4}

1. Creating Sets:
You can create a set by enclosing a sequence of elements within curly braces {} or by using the set() constructor. Sets can contain elements of any data type.

my_set1 = {1, 2, 3, 4, 5}
my_set2 = set([3, 4, 5, 6, 7])

2. Adding Elements:
You can add elements to a set using the add() method. Sets do not allow duplicate values, so adding a duplicate will have no effect.

my_set = {1, 2, 3}
my_set.add(4)  # Adds 4 to the set
my_set.add(2)  # Does not add 2 (already in the set)

3. Removing Elements:
You can remove elements from a set using the remove() or discard() method. The remove() method raises a KeyError if the element does not exist, while discard() does nothing in such cases.

my_set = {1, 2, 3, 4}
my_set.remove(3)   # Removes 3 from the set
my_set.discard(2)  # Removes 2 from the set

4. Set Operations:

Sets support various set operations like union, intersection, difference, and symmetric difference.

Union (| or union()): Combines two sets, keeping only unique elements.

set1 = {1, 2, 3}
set2 = {3, 4, 5}
union_set = set1 | set2  # or set1.union(set2)
Intersection (& or intersection()): Returns elements that are common to both sets.

set1 = {1, 2, 3}
set2 = {3, 4, 5}
intersection_set = set1 & set2  # or set1.intersection(set2)
Difference (- or difference()): Returns elements in the first set but not in the second.

set1 = {1, 2, 3}
set2 = {3, 4, 5}
difference_set = set1 - set2  # or set1.difference(set2)
Symmetric Difference (^ or symmetric_difference()): Returns elements that are in either of the sets but not in both.

set1 = {1, 2, 3}
set2 = {3, 4, 5}
symmetric_diff_set = set1 ^ set2  # or set1.symmetric_difference(set2)

5. Checking Membership:
You can check if an element is a member of a set using the in keyword.

my_set = {1, 2, 3}
is_present = 2 in my_set  # Returns True

6. Length of a Set:
You can find the number of elements in a set using the len() function.

my_set = {1, 2, 3, 4}
length = len(my_set)  # Returns 4

7. Iterating Through Sets:
You can use a for loop to iterate through the elements of a set.

my_set = {1, 2, 3}
for item in my_set:
    print(item)

Sets are commonly used for tasks that require unique values or for performing set-related operations like checking for common elements between collections, finding unique elements, or eliminating duplicates. Sets are an essential part of Python's standard library for data manipulation.

Common operations on sets inclu
de:

Adding elements: add()
Removing elements: remove(), discard()
Set operations: union(), intersection(), difference(), symmetric_difference()
Finding length: len()
Iterating: for item in my_set

 

PYTHON - TUPLES

 Tuples:


Tuples are similar to lists but are immutable (cannot be modified once created).
They are defined using parentheses ().
Tuples are often used for data that should not change during the program's execution.

In Python, a tuple is an ordered, immutable (unchangeable), and iterable collection of elements. Tuples are similar to lists but have the key difference that once you create a tuple, you cannot modify its elements. Tuples are defined using parentheses (), and elements within the tuple are separated by commas. Here, I'll explain in detail about tuples and their operations in Python.

Example:

my_tuple = (1, 2, 3, "Python", 5.0)

1. Creating Tuples:
You can create a tuple by enclosing a sequence of values or objects within parentheses. Tuples can contain elements of any data type, including numbers, strings, other tuples, or a combination of types.

my_tuple = (1, 2, 3, "Python", 5.0)

2. Accessing Elements:
You can access individual elements in a tuple by their index, just like with lists. Python uses zero-based indexing.

first_element = my_tuple[0]  # Accesses the first element (1)
third_element = my_tuple[2]  # Accesses the third element (3)

3. Immutability:
Tuples are immutable, which means you cannot change their elements after they are created. Attempting to modify a tuple will result in an error.

my_tuple[3] = "Hello"  # This will raise a TypeError


4. Tuple Packing and Unpacking:
You can pack multiple values into a single tuple or unpack a tuple into individual variables.

# Packing values into a tuple
my_packed_tuple = 1, "Python", 3.14
print(my_packed_tuple)

# Unpacking a tuple into variables
x, y, z = my_packed_tuple

5. Finding Elements:
You can use the index() method to find the index of the first occurrence of a specific value in the tuple. If the element is not found, it raises a ValueError.

index_of_2 = my_tuple.index(2)  # Finds the index of the element 2 (1)

6. Length of a Tuple:
You can find the number of elements in a tuple using the len() function.

length = len(my_tuple)  # Returns the length of the tuple (5)

7. Iterating Through Tuples:

You can use a for loop to iterate through the elements of a tuple.

for item in my_tuple:
    print(item)

8. Concatenating Tuples:
You can concatenate two or more tuples using the + operator to create a new tuple.

tuple1 = (1, 2, 3)
tuple2 = ("a", "b", "c")
concatenated_tuple = tuple1 + tuple2

9. Repetition:
You can create a new tuple by repeating an existing tuple using the * operator.

my_tuple = (1, 2)
repeated_tuple = my_tuple * 3  # Creates (1, 2, 1, 2, 1, 2)

Tuples are commonly used when you need to represent a collection of elements that should not be modified, such as coordinates, record fields, or function return values. The immutability of tuples can help ensure data integrity in your programs.

Common operations on tuples include:

Accessing elements: indexing
Unpacking: (a, b) = (1, 2)
Finding length: len()
Iterating: for item in my_tuple

Python -Lists

 Lists:


Lists are one of the most versatile and commonly used data structures in Python.
They are ordered, mutable (modifiable), and can contain elements of different data types.
Lists are defined using square brackets [].

Example:

my_list = [1, 2, 3, "Python", 5.0]

Common operations on lists include:

Adding elements: append(), insert()
Removing elements: remove(), pop()
Accessing elements: indexing and slicing
Modifying elements: direct assignment
Finding length: len()
Iterating: for item in my_list

In Python, a list is a fundamental data structure that allows you to store and manipulate collections of data. Lists are ordered, mutable (modifiable), and can contain elements of different data types. Lists are defined using square brackets [], and elements within the list are separated by commas. Here, I'll explain in detail about lists and their operations in Python.

1. Creating Lists:
You can create a list by enclosing a sequence of values or objects within square brackets. Lists can contain elements of any data type, including numbers, strings, other lists, or even a combination of types.

my_list = [1, 2, 3, "Python", 5.0]

2. Accessing Elements:
You can access individual elements in a list by their index. Python uses zero-based indexing, meaning the first element has an index of 0, the second has an index of 1, and so on.

first_element = my_list[0]  # Accesses the first element (1)
third_element = my_list[2]  # Accesses the third element (3)

3. Modifying Elements:
Lists are mutable, which means you can change their elements by assigning new values to specific indices.

my_list[3] = "Hello"  # Modifies the fourth element

4.Adding Elements:

You can add elements to the end of a list using the append() method, or insert elements at a specific index using the insert() method.

   

my_list.append(6)        # Adds 6 to the end of the list
my_list.insert(1, "A")   # Inserts "A" at index 1


        5. Removing Elements:


You can remove elements from a list by their value using the remove() method, or by their index using the pop() method. The pop() method also returns the removed element.


my_list.remove("Python")  # Removes "Python" from the list
removed_element = my_list.pop(2)  # Removes the third element (3)

6. Slicing Lists:
Slicing allows you to create sublists by specifying a range of indices. The syntax for slicing is list[start:end], where start is the inclusive index and end is the exclusive index.

sublist = my_list[1:4]  # Creates a sublist from index 1 to 3 ([2, "Hello", 6])

7. Finding Elements:
You can use the index() method to find the index of the first occurrence of a specific value in the list. If the element is not found, it raises a ValueError.

index_of_2 = my_list.index(2)  # Finds the index of the element 2 (1)

8. Length of a List:
You can find the number of elements in a list using the len() function.

length = len(my_list)  # Returns the length of the list (4)

9. Iterating Through Lists:
You can use a for loop to iterate through the elements of a list.

for item in my_list:
    print(item)

These are some of the basic operations you can perform on lists in Python. Lists are versatile and widely used in Python for tasks such as data storage, iteration, and manipulation. Understanding how to work with lists is essential for many programming tasks.

BASICS PYTHON PROGRAMMING (Arrays and Strings)

 Arrays Using Lists:


In Python, you can create arrays using lists. Lists are dynamic arrays that can hold elements of different data types.

# Creating an array using a list
my_array = [1, 2, 3, 4, 5]

# Accessing elements in the array
print(my_array[0])  # Output: 1

You can perform various operations on lists, such as appending, extending, and slicing:

# Appending an element to the end of the array
my_array.append(6)

# Extending the array with another list
my_array.extend([7, 8, 9])

# Slicing the array to get a subset
subset = my_array[2:5]  # [3, 4, 5]


Strings:

Strings are sequences of characters and are immutable.
They are defined using single quotes '' or double quotes "".
Example:

my_string = "strings are a fundamental data type"


In Python, strings are a fundamental data type, and the language provides a wide range of built-in string methods to manipulate and work with strings effectively.

str.capitalize():

This method returns a copy of the string with its first character capitalized and the rest of the characters in lowercase

text = "strings are a fundamental data type"
capitalized_text = text.capitalize()
print(capitalized_text)  # Output: "Hello world"

str.upper() and str.lower():

str.upper() converts all characters in a string to uppercase.
str.lower() converts all characters in a string to lowercase.

text = "Hello World"
upper_text = text.upper()
lower_text = text.lower()
print(upper_text)  # Output: "HELLO WORLD"
print(lower_text)  # Output: "hello world"

str.strip([chars]):

This method returns a copy of the string with leading and trailing characters (specified in the optional chars parameter) removed.

text = "   Hello, World!   "
stripped_text = text.strip()  # Removes leading/trailing spaces
print(stripped_text)  # Output: "Hello, World!"


str.replace(old, new[, count]):

This method replaces all occurrences of the old substring with the new substring in the string. You can also specify the count parameter to limit the number of replacements.

Example:

text = "Hello, World, World"
new_text = text.replace("World", "Python")
print(new_text)  # Output: "Hello, Python, Python"

str.split([sep[, maxsplit]]):

This method splits the string into a list of substrings based on the specified separator (sep). You can also specify the maximum number of splits with the maxsplit parameter.

text = "apple,banana,orange"
fruits = text.split(",")
print(fruits)  # Output: ['apple', 'banana', 'orange']

You can split a sentence into words using the split() function in Python. By default, split() separates the string at whitespace characters (spaces, tabs, and newline characters). You can also specify a custom separator if needed. Here's how you can use the split() function:

# Splitting a sentence into words using the default separator (whitespace)
sentence = "This is a sample sentence."
words = sentence.split()

# Printing the list of words
print(words)

In the example above, the split() function splits the sentence string into a list of words using whitespace as the separator.

If you want to split a sentence using a custom separator (e.g., comma or hyphen), you can pass that separator as an argument to the split() function:

# Splitting a sentence using a custom separator (e.g., comma)
sentence = "Apples,bananas,oranges"
words = sentence.split(',')

# Printing the list of words
print(words)

In this case, we used a comma as the separator to split the sentence into words.

Remember that the split() function returns a list of words, and you can then manipulate or iterate through this list as needed for your specific task

str.join(iterable):

This method concatenates elements from an iterable (e.g., a list or tuple) using the string as a separator.
Example:

fruits = ['apple', 'banana', 'orange']
joined_text = ', '.join(fruits)
print(joined_text)  # Output: "apple, banana, orange"

str.startswith(prefix[, start[, end]]) and str.endswith(suffix[, start[, end]]):

These methods check whether a string starts or ends with the specified prefix or suffix, respectively. The optional start and end parameters can be used to specify the range of characters to check.
Example:

text = "Hello, World"
starts_with_hello = text.startswith("Hello")
ends_with_world = text.endswith("World")
print(starts_with_hello)  # Output: True
print(ends_with_world)    # Output: True

These are some of the most commonly used string methods in Python. String methods make it easy to perform a wide range of operations on strings, from simple transformations to more complex manipulations. You can combine these methods to achieve more sophisticated string processing tasks.

Common string operations include:

Concatenation: +
Slicing: my_string[0:5]
Length: len(my_string)
String methods: split(), strip(), upper(), lower(), replace(), etc.

HAPPY TEACHER'S DAY TO ALL

 


Teachers are the architects of our future, shaping our minds and molding our character. Their influence is immeasurable, and their dedication is unwavering. 


ஆசிரியர்கள் நம் எதிர்காலத்தின் சிற்பிகள், நம் மனதை வடிவமைக்கிறார்கள் மற்றும் நம் குணாதிசயங்களை வடிவமைக்கிறார்கள். அவர்களின் செல்வாக்கு அளவிட முடியாதது, அவர்களின் அர்ப்பணிப்பு அசைக்க முடியாதது.


Dr. R. GNANAKUMARAN IEEE JOURNALS

 1. Robust Extreme Learning Machine based Sentiment Analysis and Classification


Abstract:
In recent times, S entimentalAnalysis (SA) acquires important attention in the process of decision making, primarily implied for the classification and extraction of the sentiments exist in the online reviews posted by the user. SA could be assumed as a sentiment classification (SC)issue where the online reviews experiences classification into negative and positive polarities based on the words available in the online reviews. This study focuses on the design of Robust Extreme Learning Machine Based Sentiment Analysis and Classification (RLM-SAC) model. The presented REIM-SAC model majorly aims to determine the nature of sentiments exist in the input data. Primarily, the input data is thoroughly pre-processed to get rid of unwanted data, which helps in enhancing the classification accuracy and minimizing the computational complexity. In addition, the presented REIM-SAC model applies ELM model to allocate proper class labels to it. To adjust the parameters of the ELM model, comprehensive learning particle swarm optimization (CLPSO) technique was used. The performance assessment of the RELM-SAC model is experimented with using benchmark database and the outcomes are scrutinized under numerous aspects. The simulation outcomes pointed out that the RELM-SAC method has obtained improved outcomes than other models.


Abstract:
The epidemic of coronavirus disease 2019 (COVID-19) has caused an ever-growing demand for treatment, testing, and diagnosis. Chest x-rays are a fast and low-cost test that can detect COVID19 but chest imaging is not a first-line test for COVID19 because of lower diagnosis performance and confounding with other viral pneumonia. Current studies using deep learning (DL) might assist in overcoming these issues as convolution neural networks (CNN) have illustrated higher performance of COVID19 diagnoses at the earlier phase. This study develops a new Firefly Optimization with Bidirectional Gated Recurrent Unit (FFO-BGRU) for COVID19 diagnoses on Chest Radiographs. The main intention of the FFO-BGRU technique lies in the recognition and classification of COVID-19 on Chest X-ray images. At the initial stage, the presented FFO-BGRU technique applies Wiener filtering (WF) technique for noise removal process. Followed, the hyperparameter tuning process takes place by using FFO algorithm and SqueezeNet architecture is applied for feature extraction. Lastly, the BGRU model is applied for COVID19 recognition and classification. A wide range of simulations were performed to demonstrate the betterment of the FFO-BGRU model. The comprehensive comparison study highlighted the improved outcomes of the FFO-BGRU algorithm over other recent approaches.