Skip to content

Commit 9496d30

Browse files
committed
long pending commits
1 parent fb94b2a commit 9496d30

File tree

85 files changed

+2074
-552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2074
-552
lines changed

.vscode/launch.json

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: Current File (Integrated Terminal)",
9+
"type": "python",
10+
"request": "launch",
11+
"program": "${file}",
12+
"console": "integratedTerminal"
13+
},
14+
{
15+
"name": "Python: Remote Attach",
16+
"type": "python",
17+
"request": "attach",
18+
"port": 5678,
19+
"host": "localhost",
20+
"pathMappings": [
21+
{
22+
"localRoot": "${workspaceFolder}",
23+
"remoteRoot": "."
24+
}
25+
]
26+
},
27+
{
28+
"name": "Python: Module",
29+
"type": "python",
30+
"request": "launch",
31+
"module": "enter-your-module-name-here",
32+
"console": "integratedTerminal"
33+
},
34+
{
35+
"name": "Python: Django",
36+
"type": "python",
37+
"request": "launch",
38+
"program": "${workspaceFolder}/manage.py",
39+
"console": "integratedTerminal",
40+
"args": [
41+
"runserver",
42+
"--noreload",
43+
"--nothreading"
44+
],
45+
"django": true
46+
},
47+
{
48+
"name": "Python: Flask",
49+
"type": "python",
50+
"request": "launch",
51+
"module": "flask",
52+
"env": {
53+
"FLASK_APP": "app.py"
54+
},
55+
"args": [
56+
"run",
57+
"--no-debugger",
58+
"--no-reload"
59+
],
60+
"jinja": true
61+
},
62+
{
63+
"name": "Python: Current File (External Terminal)",
64+
"type": "python",
65+
"request": "launch",
66+
"program": "${file}",
67+
"console": "externalTerminal"
68+
}
69+
]
70+
}

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.pythonPath": "C:\\Python37\\python.exe"
3+
}

ArgsKwArgs/KwArgs.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Example 3: Using **kwargs to pass the variable keyword arguments to the function
2+
def intro(**data):
3+
print("\nData type of argument:",type(data))
4+
5+
for key, value in data.items():
6+
print("{} is {}".format(key,value))
7+
8+
intro(Firstname="Sita", Lastname="Sharma", Age=22, Phone=1234567890)
9+
intro(Firstname="John", Lastname="Wood", Email="[email protected]", Country="Wakanda", Age=25, Phone=9876543210)
10+
# When we run the above program, the output will be
11+
12+
# Data type of argument: <class 'dict'>
13+
# Firstname is Sita
14+
# Lastname is Sharma
15+
# Age is 22
16+
# Phone is 1234567890
17+
18+
# Data type of argument: <class 'dict'>
19+
# Firstname is John
20+
# Lastname is Wood
21+
22+
# Country is Wakanda
23+
# Age is 25
24+
# Phone is 9876543210
25+
26+
27+
# In the above program, we have a function intro() with **data as a parameter. We passed two dictionaries with variable argument length to the intro() function. We have for loop inside intro() function which works on the data of passed dictionary and prints the value of the dictionary.
28+
29+
'''
30+
Things to Remember:
31+
1. *args and *kwargs are special keyword which allows function to take variable length argument.
32+
2. *args passes variable number of non-keyworded arguments list and on which operation of the list can be performed.
33+
3. **kwargs passes variable number of keyword arguments dictionary to function on which operation of a dictionary can be performed.
34+
4. *args and **kwargs make the function flexible.
35+
'''

Classes/composition.py

Whitespace-only changes.

Classes/decorators.py

Whitespace-only changes.

Classes/globalVariables.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
3+
import math
4+
5+
6+
7+
class AreaOfCircle():
8+
PI_VALUE = 3.14
9+
10+
def __init__(self, name, gender):
11+
self.name = name
12+
self.gender = gender
13+
14+
def areaCalculation(self, radius):
15+
return 3.14 * (radius**2)
16+
17+
18+
# sampleObj = AreaOfCircle()
19+
20+
# print(sampleObj)
21+
22+
# value = sampleObj.areaCalculation(5)
23+
24+
# print(value)
25+
26+
# what is the class attributes the?
27+
28+
# print(AreaOfCircle.PI_VALUE)
29+
30+
# print(sampleObj.PI_VALUE)
31+
32+
###############
33+
34+
ramObj = AreaOfCircle('Ram', 'Male')
35+
36+
print(ramObj.name)
37+
print(ramObj.gender)
38+
39+
40+
# how about this?
41+
42+
print(AreaOfCircle.name)

Classes/inheritance.py

Whitespace-only changes.

Classes/session-on-class.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
3+
class Employee():
4+
5+
def __init__(self, name, age):
6+
self.name = name
7+
self.age = age
8+
self.pi = 3.142
9+
10+
# wrong way for gettting employee name from the object.
11+
# def getEmployeeName(self, inputFromUser):
12+
# print("Employee name is ", inputFromUser)
13+
14+
def getNewEmployeeName(self):
15+
print("new employee name is ", self.name)
16+
17+
def getEmployeeAge(self):
18+
print(self.name + "'s age is " + self.age)
19+
20+
import random
21+
22+
class Bank():
23+
def __init__(self, name, age, dob, address):
24+
self.name = name
25+
self.age = age
26+
self.dob = dob
27+
self.address = address
28+
self.accountNumber = random.randint(1,1000)
29+
self.accountBalance = 0
30+
print("Your account got created, " + self.name)
31+
32+
33+
def getCustomerAccountInfo(self):
34+
print("Hello " + self.name)
35+
print("Your account got created, here's your account number " , str(self.accountNumber))
36+
print("Your current balance of your account is ", str(self.accountBalance))
37+
38+
def getMyBirthDate(self):
39+
print('Hello ' + self.name + ' you birthday is ' + self.dob)
40+
41+
42+
ramIsTheCustomer = Bank('Ram', 26, '1/1/2020', 'London')
43+
44+
ramIsTheCustomer.getCustomerAccountInfo()
45+
46+
ramIsTheCustomer.getMyBirthDate()
47+
48+
49+
50+
ram = Employee("Ram")
51+
san = Employee("Sanjay")
52+
53+
print(ram)
54+
print("--------")
55+
# print(ram.getEmployeeName("Ram"))
56+
57+
ram.getNewEmployeeName()
58+
59+
san.getNewEmployeeName()
60+
sanjay.getEmployeeAge()
61+
62+
63+
64+
65+
class EmployeeV2():
66+
def __init__(self, name, age, sex):
67+
self.name = name
68+
self.age = age
69+
self.sex = sex
70+
71+
def getEmployeeName(self):
72+
return("Employee name is " + self.name)

Classes/special_class_methods.py

Whitespace-only changes.
273 Bytes
Binary file not shown.

Cryptography/rsa.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from Crypto.PublicKey import RSA
2+
from Crypto.Cipher import PKCS1_OAEP
3+
import binascii
4+
5+
keyPair = RSA.generate(1024)
6+
7+
pubKey = keyPair.publickey()
8+
# print(f"Public key: (n={hex(pubKey.n)}, e={hex(pubKey.e)})")
9+
10+
pubKeyPEM = pubKey.exportKey()
11+
print(pubKeyPEM.decode('ascii'))
12+
13+
14+
# print(f"Private key: (n={hex(pubKey.n)}, d={hex(keyPair.d)})")
15+
privKeyPEM = keyPair.exportKey()
16+
print(privKeyPEM.decode('ascii'))
17+
18+
msg = b'D$bd1@k3'
19+
encryptor = PKCS1_OAEP.new(pubKey)
20+
encrypted = encryptor.encrypt(msg)
21+
print("Encrypted:", binascii.hexlify(encrypted))
22+
23+
24+
decryptor = PKCS1_OAEP.new(keyPair)
25+
decrypted = decryptor.decrypt(encrypted)
26+
print('\nDecrypted:', decrypted.decode("utf-8"))
27+
28+

Cryptography/test.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Basic Fernet
2+
3+
# msg = "I am going to encrypt this sentence using Fernet"
4+
msg = "D$bd1@k3"
5+
6+
from cryptography import fernet
7+
from cryptography.fernet import Fernet
8+
9+
# first generate key
10+
eKey = Fernet.generate_key()
11+
print("\nKey is : " + eKey.decode())
12+
# print("\nType of key is .. " + str(type(eKey)))
13+
print("\nKey is : " + str(len(eKey.decode())))
14+
15+
# create a class instance object
16+
f1 = Fernet(eKey)
17+
18+
eMsg = f1.encrypt(msg.encode()) # f1 instance can encrypt only bytes
19+
print("\nEncrypted message is - " + eMsg.decode())
20+
print("\nEncrypted message is -" + str(len(eMsg)))
21+
22+
# decrypt with same instance
23+
dMsg = f1.decrypt(eMsg).decode()
24+
print("\nDecrypted Message - " + dMsg)
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
org = []
2+
def getOrgNames(fromGivenInput):
3+
for orgInfo in fromGivenInput:
4+
if not orgInfo['orgName'] in org:
5+
org.append(orgInfo['orgName'])
6+
return org
7+
8+
def employeeInfoBasedOnOrg(orgName, userGivenInput):
9+
output = { orgName : []}
10+
tempOp = {}
11+
12+
for info in userGivenInput:
13+
if info['orgName'] == orgName:
14+
tempOp[info['empName']] = info['empSal']
15+
16+
output[orgName].append(tempOp)
17+
print(output)
18+
19+
if __name__ == '__main__':
20+
21+
givenInput = [
22+
{
23+
"orgName": "techM",
24+
"empName": "name1",
25+
"empSal": "40000"
26+
},
27+
{
28+
"orgName": "techM",
29+
"empName":"name2",
30+
"empSal": "5000"
31+
},
32+
{
33+
"orgName": "techM",
34+
"empName": "name3",
35+
"empSal": "50000"
36+
},
37+
{
38+
"orgName": "Mahindra",
39+
"empName": "name4",
40+
"empSal": "55000"
41+
},
42+
{
43+
"orgName": "Mahindra",
44+
"empName": "name5",
45+
"empSal": "45000"
46+
},
47+
{
48+
"orgName": "Mahindra",
49+
"empName": "name6",
50+
"empSal": "35000"
51+
}
52+
]
53+
54+
55+
listOfOrgs = getOrgNames(givenInput)
56+
57+
for orgName in listOfOrgs:
58+
employeeInfoBasedOnOrg(orgName, givenInput)
59+
60+
61+
from collections import Counter
62+
63+
eop = {}
64+
d1 = {'apple': 'sanjay', 'orange': 'sanjay', 'banana': 'sanjay'}
65+
66+
# for k,v in d1.items():
67+
# if type(v) == str:
68+
# eop[k] = len(v)
69+
70+
# print(Counter(eop))
71+
72+
print(Counter({k:len(v) for k,v in d1.items()}))

DataCollectionTypes/Dictionary/Tutorials_1.py

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
print(myDict) # Output: {'name': 'AnyName', 'id': 123, 'info': 'value of id not neccessarily need to be string since it has integer as numbers'}
99

1010
print(myDict.keys()) #Output: dict_keys(['name', 'id', 'info'])
11+
12+
13+
14+
from collections import Counter

0 commit comments

Comments
 (0)