Write Python program to Create a Dictionary with Key as First Character and Value as Words Starting with that Character


Topic: Write Python program to Create a Dictionary with Key as First Character and Value as Words Starting with that Character

Solution

string_input = '''GeeksforGeeks is a Computer Science portal for geeks. 
    It contains well written, well thought and well explained 
    computer science and programming articles, quizzes etc.'''
words = string_input.split() 
dictionary = {} 
for word in words: 
    if (word[0].lower() not in dictionary.keys()): 
        dictionary[word[0].lower()] = [] 
        dictionary[word[0].lower()].append(word) 
    else: 
        if (word not in dictionary[word[0].lower()]): 
            dictionary[word[0].lower()].append(word) 
print(dictionary) 



List all Python Programs