Words Frequency in String Shorthands

 # Using Counter() + split()

from collections import Counter

test_str = 'Python for engineers . Solution for python programs'

print("The original string is : " + str(test_str))

res = Counter(test_str.split())

print("The words frequency : " + str(dict(res)))


Program for Maximum height when coins are arranged in a triangle

def squareRoot(n):

x = n

y = 1

e = 0.000001 

while (x - y > e):

x = (x + y) / 2

y = n/x

return x

def findMaximumHeight(N):

n = 1 + 8*N

maxh = (-1 + squareRoot(n)) / 2

return int(maxh)

N = 12

print(findMaximumHeight(N))