Registry Synced

jan-2026-python-week-7-strings-3

804 words
4 min read

Strings 3

Course: Jan 2026 - Python
Strings 3
Submission deadline has passed for this assignment
Due Apr 01, 2026 at 11:59 PM IST
Instructions
Use "Test Run" to verify your code with public test cases.
Press "Submit" to have your assignment evaluated.
You can submit your assignment multiple times up until the deadline.
Make sure to submit your final code by the deadline to receive your score.
Summary
100 out of100
Score
Public Tests
3/3 Passed
Submitted on Apr 01, 2026 at 3:48 AM IST
Private Tests
3/3 Passed
Submitted on Apr 01, 2026 at 3:48 AM IST

**Change in eligibility criteria to write oppe2 exam: A5>=40/100 AND A6>=40/100 AND A7>=40/100 AND A8>=40/100. and becoming eligible to give the end term exam.


Most frequent first letter of a word in a multiline passage.**
Given a multi-line passage where the words are separated by spaces, find the letter which occurs most frequently as the first letter of any word. Consider both uppercase and lowercase letters as the same and return the letter in lowercase.
Assume there will be only one letter that occurs the most number of times as the first letter of a word.
Example:
passage = '''
word1 Word2 word3 word4 text1 text2
text3 Text4 word5 text5 word6
python1 python2 Python3
'''
The function will return "w" because "w" is the most frequently occurring first letter.
Template Code(Click to Expand)

def most_occuring_first_letter(passage: str) -> str:
    '''
    Returns the letter which occurs most frequently
    as the first letter of any word.(case insensitive)

    Args:
        passage (str): A multi-line string representing the passage.

    Returns:
        str: The most frequently occurring first letter in lowercase.
    '''
    ...


NOTE: You can use the below tools for working out and debugging. Click to open them in new tab.

Public Tests ( 3/3 )

Case 1

Input:
text
passage = '''
This is a test sentence where I wanted
to let you know that the sentences are
multi-line and words are separated by spaces.
The first letters may be of different case but you
should consider it as lowercase and return the lowercase
letter as the result. Also check the other test cases
where you can easily count the most occuring first letter.
'''
is_equal(most_occuring_first_letter(passage),'t')

Case 1

Expected Output:
text
't'

Case 1

Actual Output:
text
't'

Case 2

Input:
text
passage = '''
word1 Word2 word3 word4 text1 text2
text3 Text4 word5 text5 word6
python1 python2 Python3
'''
is_equal(most_occuring_first_letter(passage), 'w')

Case 2

Expected Output:
text
'w'

Case 2

Actual Output:
text
'w'

Case 3

Input:
text
passage='''
aaaa bbbb cccc AAAA bbbb
CCCCCC DDDDD CCCCC CdcDC
abab cDcD
'''
is_equal(most_occuring_first_letter(passage),'c')

Case 3

Expected Output:
text
'c'

Case 3

Actual Output:
text
'c'

Private Tests ( 3/3 )

Case 1

Input:
text
passage = '''
apple apricot antelope
banana berry
carrot celery cucumber
dog deer dolphin
apple acorn
'''
is_equal(most_occuring_first_letter(passage), 'a')

passage = '''
Zebra zebra ZOO
yak Yeti yellow
xylophone xerox
'''
is_equal(most_occuring_first_letter(passage), 'z')

Case 1

Expected Output:
text
'a'

'z'

Case 1

Actual Output:
text
'a'

'z'

Case 2

Input:
text
passage = '''
Hello hello Hi
Happy happy Horse
here house Hero
'''
is_equal(most_occuring_first_letter(passage), 'h')
passage = '''
quickly quiet question
quite quirky quack
quest quantum
'''
is_equal(most_occuring_first_letter(passage), 'q')

Case 2

Expected Output:
text
'h'

'q'

Case 2

Actual Output:
text
'h'

'q'

Case 3

Input:
text
passage = '''
eager eagle excellent
egg elephant
elevate extraordinary
'''
is_equal(most_occuring_first_letter(passage), 'e')
passage = '''
Eager Tagle Texcellent
egg Telephant
tele-vate text-raordinary
'''
is_equal(most_occuring_first_letter(passage), 't')

Case 3

Expected Output:
text
'e'

't'

Case 3

Actual Output:
text
'e'

't'

💻 IITM Official Solution

python

def most_occuring_first_letter(passage: str) -> str:
    '''
    Returns the letter which occurs most frequently
    as the first letter of any word.(case insensitive)

    Args:
        passage (str): A multi-line string representing the passage.

    Returns:
        str: The most frequently occurring first letter in lowercase.
    '''


    first_letter_counts = {}
    for word in passage.lower().split():
        first_letter = word[0]
        if first_letter not in first_letter_counts:
            first_letter_counts[first_letter] = 0
        first_letter_counts[first_letter] += 1

    return max(first_letter_counts, key=first_letter_counts.get)


💻 My Submitted Code

python
def most_occuring_first_letter(passage: str) -> str:
    # Split the passage into words (handles spaces and newlines automatically)
    words = passage.split()
    if not words:
        return ""

    counts = {}
    for word in words:
        # Get first char, convert to lowercase for case-insensitivity
        first_char = word[0].lower()
        counts[first_char] = counts.get(first_char, 0) + 1

    # Find the key with the maximum value
    # max() with key=counts.get returns the key that has the highest count
    return max(counts, key=counts.get)

Document Outline
Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.