- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to find all close matches of input string from a list
In this tutorial, we are going to find a solution to a problem. Let's see what the problem is. We have a list of strings and an element. We have to find strings from a list in which they must closely match to the given element. See the example.
Inputs strings = ["Lion", "Li", "Tiger", "Tig"] element = "Lion" Ouput Lion Li
We can achieve this by using the startswith built-in method. See the steps to find the strings.
- Initialize string list and a string.
- Loop through the list.
- If string from list startswith element or element startswith the string from the list
Print the string
Example
## initializing the string list strings = ["Lion", "Li", "Tiger", "Tig"] element = "Lion" for string in strings: ## checking for the condition mentioned above if string.startswith(element) or element.startswith(string): ## printing the eligible string print(string, end = " ") print()
If you run the above program,
Output
Lion Li
If you have any doubts regarding the program, please do mention them in the comment section.
- Related Articles
- Java program to find all close matches of input string from a list
- Find all close matches of input string from a list in Python
- Program to find list of all possible combinations of letters of a given string s in Python
- Python program to get all pairwise combinations from a list
- Python program to find the String in a List
- Python Program to get all unique keys from a List of Dictionaries
- Python program to find all duplicate characters in a string
- How can I find all matches to a regular expression in Python?
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Python Program to check whether all elements in a string list are numeric
- Java Program to check if none of the string in the list matches the condition
- Python program to print all sublists of a list.
- Program to find a good string from a given string in Python
- Python Check if suffix matches with any string in given list?
- Python Program to Find Number of Occurrences of All Elements in a Linked List

Advertisements