test_list = [[4, 5, 8], [8, 1, 20], [7, 12, 10]]
print("The original list is : " + str(test_list))
K = 2
res = [sub[K] for sub in test_list]
print("The Kth column of matrix is : " + str(res))
Solve Problems by Coding Solutions - A Complete solution for python programming
test_list = [[4, 5, 8], [8, 1, 20], [7, 12, 10]]
print("The original list is : " + str(test_list))
K = 2
res = [sub[K] for sub in test_list]
print("The Kth column of matrix is : " + str(res))
# 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)))
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))
import math
def productPrimeFactors(n):
product = 1
if (n % 2 == 0):
product *= 2
while (n%2 == 0):
n = n/2
for i in range (3, int(math.sqrt(n)), 2):
if (n % i == 0):
product = product * i
while (n%i == 0):
n = n/i
if (n > 2):
product = product * n
return product
n = 44
print (int(productPrimeFactors(n)))
import numpy as np
arr = [[14, 17, 12, 33, 44],
[15, 6, 27, 8, 19],
[23, 2, 54, 1, 4,]]
print("\narr : \n", arr)
print("\n50th Percentile of arr, axis = None : ",
np.percentile(arr, 50))
print("0th Percentile of arr, axis = None : ",
np.percentile(arr, 0))
print("\n50th Percentile of arr, axis = 0 : ",
np.percentile(arr, 50, axis =0))
print("0th Percentile of arr, axis = 0 : ",
np.percentile(arr, 0, axis =0))