Problem
Write a program that takes a sentence as input from the user and computes the frequency of each letter. Use a variable of dictionary type to maintain the count.
s = input('Enter any string: ') freq = { } for ch in s : if ch in freq : freq[ch] += 1 else : freq[ch] = 1 print ('Count of all characters is: ', freq) for key, val in freq.items( ) : print(key, ':', end = '') for i in range(0, val) : print('*', end ='') print( )
Interaction
Enter any string: A very talented individual Count of all characters is: {'A': 1, ' ': 3, 'v': 2, 'e': 3, 'r': 1, 'y': 1, 't': 2, 'a': 2, 'l': 2, 'n': 2, 'd': 3, 'i': 3, 'u': 1} A :* :*** v :** e :*** r :* y :* t :** a :** l :** n :** d :*** i :*** u :*
Problem
Write a program that deletes every kth element, and return the modified list, For example, if we wish to delete every 3rd element from the list [10, 20, 30, 40, 50, 60, 70, 80, 90, 100], the output list will be [10, 20, 40, 50, 70, 80, 100].
lst1= [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] k = 3 lst2 = [x for i, x in enumerate(lst1) if (i + 1) % k != 0] print(lst2)
Interaction
[10, 20, 40, 50, 70, 80, 100]
Problem
xyz
Interaction