- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 – Test String in Character List and vice-versa
When it is required to test string in character list and vice-versa, a simple ‘in’ operator and ‘join’ method are used.
Below is a demonstration of the same −
my_string = 'python' print("The string is :") print(my_string) my_key = ['p', 'y', 't', 'h', 'o', 'n', 't', 'e', 's', 't'] print("The key is ") print(my_key) joined_list = ''.join(my_key) my_result = my_string in joined_list print("The result is :") if(my_result == True): print("The string is present in the character list") else: print("The string is not present in the character list")
The string is : python The key is ['p', 'y', 't', 'h', 'o', 'n', 't', 'e', 's', 't'] The result is : The string is present in the character list
A string is defined and displayed on the console.
The value for key is defined and displayed on the console.
The elements of the key are joined to make a string using .join() function.
This is assigned to a variable.
The string and the key are compared to see if string is present in the above mentioned list.
This result is assigned to a variable.
Based on the Boolean value in this result, the relevant message is displayed on the console.
- Adding Tuple to List and vice versa in Python
- Convert string to DateTime and vice-versa in Python
- Converting string to number and vice-versa in C++
- Binary to decimal and vice-versa in Python
- How to convert String to StringBuilder and vice versa Java?
- How do I serialize a Python dictionary into a string and vice versa?
- Java Program to Convert the ArrayList into a string and vice versa
- Converting Strings to Numbers and Vice Versa in Java.
- How to Convert a String to Hexadecimal and vice versa format in java?
- C Program for LowerCase to UpperCase and vice-versa
- Convert from any base to decimal and vice versa in C++
- C program to convert upper case to lower and vice versa by using string concepts
- C++ Program to Convert Binary Number to Decimal and vice-versa
- C++ Program to convert Octal Number to Decimal and vice-versa
- C++ Program to Convert Binary Number to Octal and vice-versa