## Blog Pages

### Vertical concatenation in matrix using loop

sample_list = [["Hi", "python"], ["welcome", "for"], ["to","engineers"]]

print("The original list : " + str(sample_list))

res = []

N = 0

while N != len(sample_list):

temp = ''

for idx in sample_list:

try: temp = temp + idx[N]

except IndexError: pass

res.append(temp)

N = N + 1

res = [ele for ele in res if ele]

print("List after column Concatenation : " + str(res))

### Find number of times every day occurs in a Year

import datetime

import calendar

def day_occur_time(year):

days = [ "Monday", "Tuesday", "Wednesday",

"Thursday", "Friday", "Saturday",

"Sunday" ]

L = [52 for i in range(7)]

pos = -1

day = datetime.datetime(year, month = 1, day = 1).strftime("%A")

for i in range(7):

if day == days[i]:

pos = i

if calendar.isleap(year):

L[pos] += 1

L[(pos+1)%7] += 1

else:

L[pos] += 1

for i in range(7):

print(days[i], L[i])

year = 2020

day_occur_time(year)

### Program to count uppercase, lowercase, special character and numeric values using Regex

import re

string = "Pythonforengineers !,* 12345"

uppercase_characters = re.findall(r"[A-Z]", string)

lowercase_characters = re.findall(r"[a-z]", string)

numerical_characters = re.findall(r"[0-9]", string)

special_characters = re.findall(r"[, .!?*]", string)

print("The no. of uppercase characters is", len(uppercase_characters))

print("The no. of lowercase characters is", len(lowercase_characters))

print("The no. of numerical characters is", len(numerical_characters))

print("The no. of special characters is", len(special_characters))

### Program to find LCM

def calculate_lcm(x, y):

if x > y:

greater = x

else:

greater = y

while(True):

if((greater % x == 0) and (greater % y == 0)):

lcm = greater

break

greater += 1

return lcm

num1 = int(input("Enter first number: "))

num2 = int(input("Enter second number: "))

print("The L.C.M. of", num1,"and", num2,"is", calculate_lcm(num1, num2))

### Program to find Smallest K digit number divisible by X

MIN = pow(10, K-1)

if(MIN%X == 0):

return (MIN)

else:

return ((MIN + X) - ((MIN + X) % X))

X = 83;

K = 5;