
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python – Strings with all given List characters
When it is required to find the strings which have all the given characters present in a list, a method is defined that takes the string as a parameter and iterates through the string, and adds the index value to it.
Example
Below is a demonstration of the same −
print("Method definition begins...") def convert_to_my_string(my_string): my_result = "" for index in my_string: my_result += index return my_result print("Method definition ends...") my_string = ['L','e','a','r','n','P','y','t','h','o','n', 'c', 'o', 'o', 'l', 'f', 'u', 'n'] print("The list is : " ) print(my_string) print("The resultant string is : ") print(convert_to_my_string(my_string))
Output
Method definition begins... Method definition ends... The list is : ['L', 'e', 'a', 'r', 'n', 'P', 'y', 't', 'h', 'o', 'n', 'c', 'o', 'o', 'l', 'f', 'u', 'n'] The resultant string is : LearnPythoncoolfun
Explanation
A method named ‘convert_to_my_string’ is defined that takes a string as a parameter.
An empty string is defined.
The original parameter is iterated over, and the element is added to the empty string.
This is returned as output.
Outside the method, a list of characters is defined and is displayed on the console.
The method is called by passing every character to it.
The result is displayed as the output on the console.
- Related Articles
- Python Program – Strings with all given List characters
- Python Program to Extract Strings with at least given number of characters from other list
- Python – Filter all uppercase characters from given list of tuples
- Convert list of strings and characters to list of characters in Python
- Python - Find all the strings that are substrings to the given list of strings
- Python program to replace all Characters of a List except the given character
- Python – Filter Tuples with Strings of specific characters
- Converting all strings in list to integers in Python
- Python – Equidistant consecutive characters Strings
- Find all triplets in a list with given sum in Python
- Python – All occurrences of Substring from the list of strings
- Python program – All occurrences of Substring from the list of strings
- Python program to Sort a List of Strings by the Number of Unique Characters
- Find all strings formed from characters mapped to digits of a number in Python
- Python – Rows with all List elements

Advertisements