INTERVIEW QUESTIONS
INTERVIEW QUESTIONS
=====================
#regular exp
# from re import findall
#
# r = findall('[0-9]',s)
# total = [int(i) for i in r]
# print(sum(total))
#regular exp:
# jo = ''.join(l)
# res = findall('[0-9]+', jo)
# print(res)
# print()
#46.
#l = [1,3,5,7]
# #o/p-->[1,9,25,49]
# squ = lambda x : x ** 2
# print(list(map(squ, l)))
# external = 0
# for i in l:
# for j in i:
# external += j
# print(external)
# for i,j,k in l:
# internal = 0
# external = []
# internal = i+j+k
# external += [i+j+k]
# print(internal)
# print(external)
#or
# intrnl = [sum(i) for i in l]
# print(intrnl)
# extrnl = sum(intrnl)
# print(extrnl)
# print(s[::-1])
#print(list(reversed(s)))
# print(word_count)
# #dict comprehension
# print({name: names.count(name) for name in names})
# print()
# n = 0
# for num in numbers:
# if num > n:
# n = num
# print(n)
# for i in range(len(numbers)-1):
# if numbers[i] > numbers[i+1]:
# numbers[i], numbers[i+1] = numbers[i+1],
numbers[i]
# print(numbers[-1])
# for i in range(len(numbers)):
# for j in range(len(numbers)-1):
# if numbers[j] > numbers[j+1]:
# numbers[j],numbers[j + 1] = numbers[j+1],
numbers[j]
# print(numbers[-1])
#print()
# import math
# def is_perfectsqu(num):
# res = num//2
# for i in range(res):
# if i * i == num:
# return True
# #return f'{num}--> is a perfect square'
# return False
# # return f'{num}--> is not a perfect square'
#
# print(is_perfectsqu(11))
# print(is_perfectsqu(169))
# print(is_perfectsqu(256))
#OR
# import math
# def is_perfectsq(num):
# res = math.sqrt(num)
# if res == int(res):
# return True
# else:
# return False
#
# print(is_perfectsq(25))
# perfect num
# def is_perfectnum(num):
# res = 0
# for i in range(1,num):
# if num % i == 0:
# res += i
# print(num==res)
#or
# res = {}
# for name,count_ in count_pair.items():
# if count_ > 1:
# res[name] = count_
# print(res)
#print()
# products = defaultdict(list)
#
# for product in all_products:
# if product in apple_products:
# products['apple_products'] += [product]
#
# elif product in google_products:
# products['google_products'] += [product]
#
# elif product in windows_products:
# products['windows_products'] += [product]
#
# print(products)
# apple = []
# google = []
# windows = []
# d = defaultdict(list)
# for item in all_products:
# if item.startswith('i') or item.startswith('m'):
# d['apple'] += [item]
#
# elif item.startswith('g'):
# d['google'] += [item]
#
# else:
# d['windows'] += [item]
# print(d)
#hard-coding
# for product in all_products:
# if product == 'iphone' and product == 'mac' and
product == 'iwatch' and product == 'ios':
# apple_products.append(product)
#
# elif product == 'gmail' and product == 'google
maps' and product == 'google drive':
# google_products.append(product)
#
# elif product == 'windows' and product == 'one
drive':
# windows_products.append(product)
#
# products = defaultdict(list)
# for product in all_products:
# if product in apple_products:
# products['apple_products'] += [product]
#
# elif product in google_products:
# products['google_products'] += [product]
#
# elif product in windows_products:
# products['windows_products'] += [product]
# print(products)
#or
# count = 0
# for i in s:
# if i == ' ':
# count += 1
# print(count)
#81. theory
#95. WAP to sort the list which is mix of both odd and
even numbers, the sorted
# list should have odd numbers first and then even
numbers in sorted order.
# l = [3,4,1,7,2,12,8,6,9,11]
# #odd = [3,1,7,9,11]--> [1,3,7,9,11]
# #even = [4,2,12,8,6]--> [2,4,6,8,12]
#
# odd = []
# even = []
# for i in l:
# if i % 2 != 0:
# odd.append(i)
#
# else:
# even.append(i)
#
# res = sorted(odd) + sorted(even)
# print(res)
#96. WAP to sort the list which is mix of both odd and
even numbers, the sorted
# list should have odd numbers be in ascending order
and even numbers in
# descending order.
#l = [3,4,1,7,2,12,8,6,9,11]
# #odd = [3,1,7,9,11]--> [1,3,7,9,11]
# #even = [4,2,12,8,6]--> [12,8,6,4,2]
# odd = []
# even = []
# for i in l:
# if i % 2 != 0:
# odd.append(i)
#
# else:
# even.append(i)
#
# res = sorted(odd) + sorted(even,reverse= True)
# print(res)
#or
# def total_len(args):
# length = 0
# for i in args:
# length += len(i)
#
# return length
#
# print(total_len(([1, 2, 3], (4,5), ['apple',
'google', 'yahoo', 'gmail'],
# (1,2,3), {'a':1, 'b': 2})))
# for i in s:
# if i == ' ':
# res = s.replace(i, '\n')
# print(res)
# result = '\n'.join(s.split())
# print(result)
#or
# from re import sub
# res = sub('["AEIOUaeiou"]', '*', s)
# print(res)
# sort = sorted(numbers)
# add_min = sum(sort[:3])
# add_max = sum(sort[-3:])
# print(sort)
# print(add_min, add_max)
# numbers = [10, 15, 20, 25, 30, 35, 40, 15, 15]
# sort = sorted(numbers)
# add_max = sum(sort[0:3:1])
# add_min= sum(sort[-3:len(numbers):1])
# print(sort)
# print(add_max,add_min)
# print(numbers[0:3:1])
# print()
# import re
# print(re.findall(r'p\w+',s))
#or
# from re import findall
# res = findall('[a-z]+', s)
# print(res)
#print()
#or
# l = []
# for i in num:
# if i.endswith('5'):
# l.append(int(i))
# print(l)
#or
# s = 'Banglore'
# i = 1
# while i <= 10:
# print(s)
# i += 1
#print()
#or
# from re import findall
# result = findall(r'\bh[a-z]+\b', s)
# print(' '.join(result))
#
# a = [3, 5, -4, 8, 11, 1, -1, 6]
# for i in a:
# for j in a:
# if i - j == 10 or i +j == 10 and i !=j :
# print(i,j)
#or
# res = []
# for i in l:
# for j in l:
# if i-j == 10 or j-i == 10 or i+j == 10:
# res.append((i,j))
# print(res)
#print()
#136.What is pylint?
#solu : It is a static code analysis tool to identify
errors in Python code
# and helps programmers enforce good coding style.
# This tool enables them debugging complex code with
less manual work.
# It is one of the tools which gets used for test-
driven development (TDD)
#print()
# def Divexp(a,b):
# assert a > 0, 'Error'
# if b == 0:
# raise ZeroDivisionError
#
# else:
# c = a/b
# return c
#
# a = eval(input('enter a:'))
# b = eval(input('enter b:'))
# # print(Divexp(a,b))
#OR.
# batch = [ 40, 26, 39, 30, 25, 21]
# cut = int(input('enter c:'))
# for i in batch:
# assert i > cut, "Batch is Rejected"
# print (str(i) + " is O.K" )
#print()
#while loop
# i = 1
# while i <= 5:
# j = 1
# while j <= i:
# print(j, end = ' ')
# j += 1
# print()
# i += 1
# # print()
#print()
#or
#from re import findall
# result = ''.join(items)
# l = []
# r = findall('[\d\.\d]+', result)
# for i in r:
# l.append(float(i))
# print(l)
#146.
def modify(list):
res = []
for i in list:
if i %3 == 0:
i = 33
res += [i]
else:
res+= [i]
return res
print(modify([2,3,7,8,12,8,50,63,100]))
#147.
#1 2 3 *
#1 2 * 4
#1 * 3 4
#* 2 3 4