- 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 program to find the character position of Kth word from a list of strings
When it is required to find the character position of ‘K’th word from a list of strings, a list comprehension along with enumerate is used.
Below is a demonstration of the same −
my_list = ["python", "is", "fun", "to", "learn"] print("The list is :") print(my_list) K = 15 print("The value of K is :") print(K) my_result = [element for sub in enumerate(my_list) for element in enumerate(sub)] my_result = my_result[K] print("The result is :") print(my_result)
The list is : ['python', 'is', 'fun', 'to', 'learn'] The value of K is : 15 The result is : 2
A list of strings is defined and is displayed on the console.
A value for ‘K’ is defined and is displayed on the console.
A list comprehension is used to iterate over the elements of the list using enumerate.
The zeroth element in every element is accessed using enumerate
This is converted to a list.
Since enumerate is used, the output would be an integer here.
The ‘K’th element of this list is displayed as the output on the console.
- Program to find the kth missing number from a list of elements in Python
- Python program to find word score from list of words
- Program to find the largest grouping of anagrams from a word list in Python
- Program to find longest common prefix from list of strings in Python
- Program to reverse the position of each word of a given string in Python
- Program to find largest kth index value of one list in Python
- Program to find out if the strings supplied differ by a character in the same position in Python
- Python Program to return the Length of the Longest Word from the List of Words
- Program to find the kth factor of n using Python
- Python program – All occurrences of Substring from the list of strings
- Find frequency of given character at every position in list of lists in Python
- Python – Test for Word construction from character list
- In MySQL, which function we can use to find the index position of a particular string from a list of strings?
- Program to find the kth character after decrypting a string in C++
- Python program for most frequent word in Strings List