My Personal Notes Don't Get Into It 😂
'''from __future__ import print_function'''
"""for i in range(4):
print("printing")
if i==2:
continue
print(i)"""
"""l=[1,4,7]
for item in l:
pass"""
"""def greet(name):
greet= "hello"+ " "+name
return greet
a=greet('Aamir')
print(a)"""
'''def factorial(n):
for i in range(10):
"""if i == 5 or i == 6:
return 1
else:
return n * factorial(n-1)"""
print(factorial(8))'''
'''class sample:
a="Aamir"
obj=sample()
obj.a="noor"
print(sample.a)
print(obj.a)'''
'''n = int(input())
i=1
while i<=n:
print(i,end="")
i+=1'''
'''n=int(input())
for i in range(n):
print(i+1, end ='')'''
'''n= int(input("enter a number"))
for i in range (n):
print(i+1,end="")'''
'''for i in range(10):
print (i,end="")'''
'''def addition(n):
return n + n'''
# We double all numbers using map()
'''numbers = (1, 2, 3, 4)
result = map(addition, numbers)
print(list(result))'''
# Double all numbers using map and lambda
'''numbers = (1, 2, 3, 4)
result = map(lambda x: x + x, numbers)
print(list(result))'''
# Add two lists using map and lambda
'''numbers1 = [1, 2, 3]
numbers2 = [4, 5, 6]
result = map(lambda x, y: x + y, numbers1, numbers2)
print(list(result))'''
# List of strings
'''l = ['sat', 'bat', 'cat', 'mat']'''
# map() can listify the list of strings individually
'''test = list(map(list, l))
print(test)
Output :
[['s', 'a', 't'], ['b', 'a', 't'], ['c', 'a', 't'], ['m', 'a', 't']]'''
## Hackerrank list comprehension...Question--
'''dn,arr=(input() for _ in range(2))
nums = map(int, arr.split())
a=sorted(list(set(nums)))
if(len(a)==1):
print(a[0])
else:
print(a[-2])'''
'''for i in range(2,len(list1)):
if list1[i]>max:
secondmax=max
max=list1[i]
else:
if list1[i]>secondmax:
secondmax=list1[i]
print(secondmax) '''
##End
# nested lists question
'''d={} #1
for _ in range(int(raw_input())): #2
Name=raw_input() #3
Grade=float(raw_input()) #4
d[Name]=Grade #5
v=d.values()#6
second=sorted(list(set(v)))[1] #7
second_lowest=[] #8
for key,value in d.items(): #9
if value==second: #10
second_lowest.append(key) #11
second_lowest.sort() #12
for name in second_lowest: #13
print name #14'''
'''if __name__ == '__main__':
a= []
for _ in range(int(input())):
name = input()
score = float(input())
a.append([score, name])
a.sort()
b = [i for i in a if i[0] != a[0][0]]
c = [j for j in b if j[0] == b[0][0]]
c.sort(key=lambda x: x[1])
for i in range(len(c)):
print(c[i][1])'''
'''score_list = []
for _ in range(int(input())):
name = input()
score = float(input())
score_list.append([name, score])
second_highest = sorted(set([score for name, score in score_list]))[1]
print('\n'.join(sorted([name for name, score in score_list if score == second_highest])))'''
## good way of it
'''l = []
second_lowest_names = []
scores = set()
for _ in range(int(input())):
name = input()
score = float(input())
l.append([name, score])
scores.add(score)
second_lowest = sorted(scores)[1]
for name, score in l:
if score == second_lowest:
second_lowest_names.append(name)
for name in sorted(second_lowest_names):
print(name, end='\n')'''
## end
## Percentage discussion question
'''print( format(sum(student_marks[query_name])/len(student_marks[query_name]), ".2f") )'''
# OTHER WAY
'''if __name__ == '__main__':
n = int(input())
student_marks = {}
for _ in range(n):
name, *line = input().split()
scores = list(map(float, line))
student_marks[name] = scores
query_name = input()
for key, value in student_marks.items():
if query_name == key:
sum = 0
count = 0
for i in value:
sum += i
count += 1
average = sum/count
print("{:.2f}".format(average))'''
## OTHER WAY
'''print(format((reduce(lambda x,y:x+y,student_marks[query_name]))/len(student_marks[query_name]),'.2f'))'''
### List discussion Question
'''if __name__ == '__main__':
N = int(input())
result = []
for n in range(N):
x = input().split(" ")
command = x[0]
if command == 'append':
result.append(int(x[1]))
if command == 'print':
print(result)
if command == 'insert':
result.insert(int(x[1]), int(x[2]))
if command == 'reverse':
result == result[::-1]
if command == 'pop':
result.pop()
if command == 'sort':
result == sorted(result)
if command == 'remove':
result.remove(int(x[1]))
print(result)'''
## other
'''if __name__ == '__main__':
N = int(input())
list=[]
for i in range(N):
a=input().split()
for i in range(1,len(a)):
a[i]=int(a[i])
if a[0]=="insert":
list.insert(a[1],a[2])
elif a[0]=="print":
print(list)
elif a[0]=="remove":
list.remove(a[1])
elif a[0]=="append":
list.append(a[1])
elif a[0]=="sort":
list.sort()
elif a[0]=="pop":
list.pop()
elif a[0]=="reverse":
list.reverse()'''
## Swaping Characters from lower to upper and vice-verca.
'''s = "tEstInG"
s.swapcase()
'TeSTiNg'
#end '''
''' l = [1,2,3,4,5,6]
print(l)
[1, 2, 3, 4, 5, 6]
print(*l)
output= 1 2 3 4 5 6 ###The * is known as the unpack operator. It unpacks all the elements present in an iterable.
print(*map(lambda x : x**2, l))
1 4 9 16 25 36 '''
'''def is_leap(year):
leap = False
if year % 4 == 0:
leap = True
if year % 100 == 0:
leap = False
if year % 400 == 0:
leap = True
return leap
year = int(input())'''
'''print "Hello %s %s! You just delved into python." % (input(), input())'''
'''print(f"Hello {input()} {input()}! You just delved into python.")'''
## what is f" ?
## This is a string formatting mechanism known as F-strings. F-strings are used to embed expressions inside string literals for formatting.
'''And important point to note is that F-strings formatting are faster than '% formatting' and 'str.format()'.
I hope this clears your query.'''
## Below is stuff that you may do in free time.
'''import math
c='♥'
width = 40
print ((c*2).center(width//2)*2)
for i in range(1,width//10+1):
print (((c*int(math.sin(math.radians(i*width//2))*width//4)).rjust(width//4)+
(c*int(math.sin(math.radians(i*width//2))*width//4)).ljust(width//4))*2)
for i in range(width//4,0,-1):
print ((c*i*4).center(width))
print ((c*2).center(width))'''
## End
## Hackerrank:- Text Wrap Question
'''import textwrap
s = input()
w = int(input())
l = " ".join(textwrap.wrap(s,w))
print(textwrap.fill(l,w))'''
## But this didnt work. ## check it why?
'''textwrap.fill(text, width)
Wraps the single paragraph in text, and returns a single string containing the wrapped paragraph. fill() is shorthand for "\n".join(wrap(text, ...))
So you don't have to use both .join() and .fill()'''
'''Try this:
def wrap(string, max_width):
l= list()
for i in range(0,len(string),max_width): l.append(string[i:i+max_width])
return "\n".join(l)'''
'''def wrap(string, max_width):
s = ""
for c in range(0,len(string),max_width):
s += string[c:c+max_width] + "\n"
return s'''
'''l1=list(map(chr,range(97,123)))
print(l1)
x=l1[n-1]'''
'''import string
a=string.ascii_uppercase
print(a)'''
'''l=[1,2,3,4]
print(l)'''
## Some Concept
# Python 3
'''print(input().title()) will not work because the question is asking to capitalise firse letter of each word keeping in mind that "if it is a letter". Title and Capitalise are different in function as:
'abcd'.title()
results in 'Abcd' but
'12abcd'.title()'''
'''Hello, The star symbol is called a "splat" operator in python. The way it works is separates each item in the tuple as individuals.
print(*[1, 2, 3])
This prints
1 2 3
instead of
[1, 2, 3]'''
'''list=[]
for i in range(N):
a=input().split()
for i in range(1,len(a)):
a[i]=int(a[i])
if a[0]=="insert":
list.insert(a[1],a[2])
elif a[0]=="print":
print(list)
elif a[0]=="remove":
list.remove(a[1])
elif a[0]=="append":
list.append(a[1])
elif a[0]=="sort":
list.sort()
elif a[0]=="pop":
list.pop()
elif a[0]=="reverse":
list.reverse()'''
#n=17
#number=int(input("enter number:="))
'''def print_formatted(number):
number=int(input("enter number:="))
length=len("{0:b}".format(number))
for i in range(1,number+1):
print_formatted("{0:{w}d} {0:{w}o} {0:{w}X} {0:{w}b}".format(i, w=length)) '''
'''number=25
length=len("{0:b}".format(number))'''
##'N{DEGREE SIGN}' use this to print degree sign
##hold alt and type 0176
## Print Upto 2 Decimal Places..
'''“how to print value to only 3 decimal places python” Code Answer's
print(format(432.456, ".2f"))
>> 432.45.
print(format(321,".2f"))
>> 321.00. '''
## Worked For Average
'''array=[1,2,3,4]
print(sum(array)/len(array))'''
#Understand Delimiter
'''>> a = raw_input()
5 4 3 2
>> lis = a.split()
>> print (lis)
['5', '4', '3', '2']''' ## Strings
'''If the list values are all integer types, use the map() method to convert all the strings to integers.
>> newlis = list(map(int, lis))
>> print (newlis)
[5, 4, 3, 2]''' ## Integers
## To print string item in list Line by line:--
'''list=combination
for i in combination:
print(''.join(i))'''
## a= Think of it:-
'''Sample Output
A
C
H
K
AC
AH
AK
CH
CK
HK
## Solution:--
word,number=input().split()
from itertools import combinations
#a=combinations(word,number)
#a=sorted(a)
for i in range(1,int(number)+1):
for j in combinations(sorted(word),i):
print(''.join(j))'''
## End of a
##
'''>>> a = [2, 3, 5, 7, 11, 13]
>>> for x in a: print(x, end=" ") ## In a single line with space separated.
2 3 5 7 11 13'''
## print(x,end="\n") # In New line Remember
'''a=[1,2,3,4]
print(*a)
print(a)'''
## groupby Concepts:--
# Enter your code here. Read input from STDIN. Print output to STD
'''from itertools import groupby
print(*[(len(list(c)),int(k)) for k,c in groupby(input())])
## Explanation:--Sure thing. Basically I'm unpacking the list comprehension and printing each element of it.
The list is built of elements of (len(list(c)), int(k)). len(list(c)) is simply the number of occurences of a character c returned by the groupby function. k is just the key value, the character itself.
Hope this helps, let me know if you have any other questions about anything specific.###
from itertools import groupby
print(*[(len(list(c)), int(k)) for k, c in groupby(input())])'''
'''groups = []
uniquekeys = []
data = sorted(data, key=keyfunc)
for k, g in groupby(data, keyfunc):
groups.append(list(g)) # Store group iterator as a list
uniquekeys.append(k)'''
# End Of groupby
## Set Concepts
'''n1=int(input())
set1=set(input().split())
n2=int(input())
set2=(input().split())
print(len(set1.difference(set2))) # Use for set2 as list
print(len(set1-set2)) # Use both set as set.'''
Comments
Post a Comment