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
Programming Articles - Page 1616 of 3366
4K+ 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
213 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
57K+ 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
2K+ 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
459 Views
In this article, we are going to learn about the pytrie module to prefix matching strings from a list of strings. Let's see an example to understand it clearly.Input: List: ['tutorialspoint', 'tutorials', 'tutorialspython', 'python'] Prefix: 'tutorials' Output: ['tutorialspoint', 'tutorials', 'tutorialspython']We can achieve it in different ways. In this tutorial, we are going to achieve it using the pytrie module.From pytrie module, we will use the pytrie.StringTrie data structure. We can perform create, insert, search, and delete operations.First, install the pytrie module with the following command.pip install pytrieLet's see steps to achieve the desired output.Import the pytrie module.Initialize the list, ... Read More
4K+ Views
In this article, we are going to learn how to validate a form in django. Django comes with build-in validators for forms. We can use them in the tutorial to validate forms.You must familiar with the Django to follow along with this tutorial. If you are not familiar with Django, then this article is not for you.Set up the basic Django project with the following commands.mkdir form_validation cd form_validation python -m venv env (Activate environment based on your OS) pip install django===3.0 django-admin startproject form_validation . (Don't forget dot(.) at the end) python manage.py startapp ... Read More