VOOZH about

URL: https://www.geeksforgeeks.org/python/python-program-to-find-the-character-position-of-kth-word-from-a-list-of-strings/

⇱ Python program to find the character position of Kth word from a list of strings - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python program to find the character position of Kth word from a list of strings

Last Updated : 15 Jul, 2025

Given a list of strings. The task is to find the index of the character position for the word, which lies at the Kth index in the list of strings.

Examples:

Input : test_list = ["geekforgeeks", "is", "best", "for", "geeks"], K = 21 
Output : 0
Explanation : 21st index occurs in "geeks" and point to "g" which is 0th element of word.

Input : test_list = ["geekforgeeks", "is", "best", "for", "geeks"], K = 15 
Output : 1
Explanation : 15th index occurs in "best" and point to "e" which is 1st element of word.

Method #1 : Using enumerate() + list comprehension

In this, we use nested enumerate() to check indices for words, and strings in the list, list comprehension is used to encapsulate logic in 1 liner.


Output
The original list is : ['geekforgeeks', 'is', 'best', 'for', 'geeks']
Index of character at Kth position word : 2

Time Complexity: O(n2)
Auxiliary Space: O(n)

Method #2 : Using next() + zip() + count()

In this, we pair up the number of words with their counts using zip(), and accumulate till we don't reach Kth Index.


Output
The original list is : ['geekforgeeks', 'is', 'best', 'for', 'geeks']
Index of character at Kth position word : 2

Time Complexity: O(n2)
Auxiliary Space: O(n)

Method 3:  Using nested loop


Output
The original list is : ['geekforgeeks', 'is', 'best', 'for', 'geeks']
Index of character at Kth position word : 2
Comment