You are on page 1of 15

Python program to create a dictionary from a string and count the

letters from the string.

Program

st = input("Enter a string: ")


dic = {} #creates an empty dictionary
for ch in st:
    if ch in dic: #if next character is already in the dictionary
        dic[ch] += 1
    else:
        dic[ch] = 1 #if ch appears for the first time
for key in dic:
    print(key,':',dic[key])

output

enter the string

ENGINEERING

E- 3

N- 2

G -2

I -2

R -1
Python program that accepts a comma separated sequence of
words as input and prints the unique words in sorted form.

program
items = input("Input comma separated sequence of words")

words = [word for word in items.split(",")]

print(",".join(sorted(list(set(words)))))

OUTPUT

Input comma separated sequence of words red, black, pink, green

black, green, pink, red

You might also like