
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

11K+ Views
In this article, we are going to see different ways to find the last occurrence of an element in a list.Let's see how to find the last occurrence of an element by reversing the given list. Follow the below steps to write the code.Initialize the list.Reverse the list using reverse method.Find the index of the element using index method.The actual index of the element is len(list) - index - 1.Print the final index.ExampleLet's see the code. Live Demo# initializing the list words = ['eat', 'sleep', 'drink', 'sleep', 'drink', 'sleep', 'go', 'come'] element = 'sleep' # reversing the list words.reverse() ... Read More

148 Views
In this article, we are going see how to use ldexp() function. This is one of the methods from the math library.The function ldexp(first, second) take two valid number either positive or negative and returns the result of first * (2 ** second). Let's see some examples.Example Live Demo# importing the math library import math # using the function ldexp print(math.ldexp(1, 4)) print(math.ldexp(5, -4)) print(math.ldexp(-3, -1))If you run the above code, then you will get the following result.Output16.0 0.3125 -1.5We will get error if we pass arguments other than numbers to the ldexp function. Let's see an example.Example Live Demo# importing ... Read More

3K+ Views
In this article, we are going to learn how to apply a linear search on lists and tuples.A linear search starts searching from the first element and goes till the end of the list or tuple. It stops checking whenever it finds the required element.Linear Search - Lists & TuplesFollow the below steps to implement linear search on lists and tuples.Initialize the list or tuple and an element.Iterate over the list or tuple and check for the element.Break the loop whenever you find the element and mark a flag.Print element not found message based on the flag.ExampleLet's see the code.# ... Read More

3K+ Views
In this article, we are going to learn how to get alternate elements from the list. We'll see two different ways to solve the problem.Follow the below steps to solve the problem in one way.Initialize the list.3Iterate over the list and store all the elements from the odd index.Print the result.ExampleLet's see the code. Live Demo# Initializing the list numbers = [1, 2, 3, 4, 5] # finding alternate elements result = [numbers[i] for i in range(len(numbers)) if i % 2 != 0] # printing the result print(result)If you run the above code, then you will get the following ... Read More

206 Views
In this article, we are going to learn how to expand the list by replicating the element K times. We'll two different ways to solve the problem.Follow the below steps to solve the problem.Initialize the list, K, and an empty list.3Iterate over the list and add current element K times using replication operator.Print the result.ExampleLet's see the code. Live Demo# initializing the list numbers = [1, 2, 3] K = 5 # empty list result = [] # expanding the list for i in numbers: result += [i] * K # printing the list print(result)If you run ... Read More

56K+ Views
In this article, we are going to learn how to find the frequency of elements in a Python list. We can solve the problem in different ways. Let's see two of them.Follow the below steps to write the code.Initialize the list with elements and an empty dictionary.Iterate over the list of elements.Check whether the element is present in the dictionary or not.If the element is already present in the dictionary, then increase its count.If the element is not present in the dictionary, then initialize its count with 1.Print the dictionary.ExampleLet's see the code. Live Demo# initializing the list random_list = ['A', ... Read More

1K+ Views
In this article, we are going to learn how to initialize a list with alternate 0s and 1s. We'll have list length and need to initialize with alternate 0s and 1s.Follow the below steps to initialize a list with alternate 0s and 1s.Initialize an empty list and length.Iterate length times and append 0s and 1s alternatively based on the index.Print the result.ExampleLet's see the code. Live Demo# initialzing an empty list result = [] length = 7 # iterating for i in range(length): # checking the index if i % 2 == 0: # appending ... Read More

11K+ Views
In this article, we are going to learn how to convert the list of tuples into a dictionary. Converting a list of tuples into a dictionary is a straightforward thing.Follow the below steps to complete the code.Initialize the list with tuples.Use the dict to convert given list of tuples into a dictionary.Print the resultant dictionary.ExampleLet's see the code.# initializing the list tuples = [('Key 1', 1), ('Key 2', 2), ('Key 3', 3), ('Key 4', 4), ('Key 5', 5)] # converting to dict result = dict(tuples) # printing the result print(result)If you run the above code, you will get ... Read More

5K+ Views
In this article, we are going to learn how to make pairs from two lists such that no similar elements make a pair. Follow the below steps to solve the problem.Initialize the lists with elements.Iterate over the lists and append the pair into a list if the corresponding elements from the lists are not same.Print the result.ExampleLet's see the code.# initializing the lists list_1 = [1, 2, 3, 4, 5] list_2 = [5, 8, 7, 1, 3, 6] # making pairs result = [(i, j) for i in list_1 for j in list_2 if i != j] # ... Read More

1K+ Views
In this article, we are going to learn how to use SQL with Python and SQLite database. Python has a built-in module to connect with SQLite database. We are going to use sqlite3 module to connect Python and SQLite.We have to follow the below steps to connect the SQLite database with Python. Have a look at the steps and write the program.Import the sqlite3 module.Create a connection using the sqlite3.connect(db_name) the method that takes a database name is an argument. It creates one file if doesn't exist with the given name else it opens the file with the given name.Get ... Read More