Wednesday, March 23, 2022

Python tips for reference

23 March 2022

If you are using PI in python, use this:

import math

In the program, use math.pi


24 March 2022

If there is a problem where the input() or print() is not working in spite of the code running fine, check the indentation.

Use this for statistics and probability puzzles: https://brainstellar.com/

Check Codibility (MS uses) and Cocubes (JPMC uses) too


25 March 2022

To add more zeros after the decimal places, use format():

Example:

print(format(200,'.2f')

Replace the 2 in 2f with the number of zeros you need. For example, if you need 5 zeros, use.5f.


1-May-2022

    n = int(input())
    arr = list(map(intinput().split()))
    for i in range(len(arr)):
        print(i, type(i))
Here the type(i) is an integer
Output:
5 2 3 6 6 5 0 <class 'int'> 1 <class 'int'> 2 <class 'int'> 3 <class 'int'> 4 <class 'int'>
-------------------XXXXXX-----------------------------

    for i in enumerate(arr):
        print(i, type(i))
Here the type(i) is a tuple
Output:
5 2 3 6 6 5 (0, 2) <class 'tuple'> (1, 3) <class 'tuple'> (2, 6) <class 'tuple'> (3, 6) <class 'tuple'> (4, 5) <class 'tuple'>

String operations

Use split() function to split a string to list
Use join function to join the list into a string

def split_and_join(line):
    listline = line.split(" ")
    newline = "-".join(listline)
    return newline
if __name__ == '__main__':
    line = input()
    result = split_and_join(line)
    print(result)
##########################
#Create Dictionary:
d = {}
d = dict()

#With elements:
csk = {'MS Dhoni':[40,'India',4000], 'Jadeja':[34,'India',2500], 'Bravo':[39'West Indies',2300]}
print(csk)
print(type(csk))

#Another way to create dictionary:
csk = dict({'MS Dhoni':[40,'India',4000], 'Jadeja':[34,'India',2500], 'Bravo':[39'West Indies',2300]})
print(csk)
print(type(csk))

#Another way:
#csk = ([('MS Dhoni':[40,'India',4000]),('Jadeja':[34,'India',2500]),('Bravo':[39, 'West Indies',2300])])


#Accessing elements
csk['MS Dhoni']
csk.get('MS Dhoni')

#Adding elements: new entry
csk['Bravo'] = [39'WI'2000]

#another way to add element
csk.update({'Shivam Dube':[26,'India',1400]})
csk.update({'a':20})

#Update the element:
csk['MS Dhoni'][2] += 50
print(csk)

# Delete element
csk.pop('a')
print(csk)

#Viewing
#Get all keys
csk.keys()

csk.values()


csk.items()

#Iterate a dictionary:
for k,v in csk.items():
  print(k,":",v)


#Nested dictionary
ipl = {
    'csk':{'MS Dhoni': [40'India'4000], 'Jadeja': [34'India'2500], 'Bravo': [39'West Indies'2300]},
    'rr':{'samson': [28,'India',3000]},
    'srh':{'kane':[32,'NewZealand',2500]}
}
print(ipl)
print(ipl['csk'])
print(ipl['csk']['MS Dhoni'])
print(ipl['csk']['MS Dhoni'][2])



#SETS
# unordered
# contains unique elements

#create sets
s = set()
print(type(s))

#with elements
s = {1,2,3,4,5}

#accessing elements
for i in s:
  print(i)

#adding elements
s.add(6)
s.update({910}) # you can use any datatype like list or tuple or dictionary

#Delete elements from set
s.discard(10#doesnt display error if the element being removed doesnt exist
s.remove(5#displays error if the element being removed doesnt exist

#Union
a = {1,2,3,4,5}
b = {5,6,7,8}
a.union(b) # or a|b
#displays {1,2,3,4,5,6,7,8}

#Intersection
a.intersection(b) #or a&b

#Difference
a.difference(b) # or a-b
#displays elements of A only minus intersection

#symmetric difference
a.symmetric_difference(b) #a^b
#intersection doesnt appear .. only elements of a and b


Wednesday, March 22, 2017

Remove Protected View Completely (Registry hack)

Remove Protected View Completely.

This is a registry hack and ensure that the user doing this has complete mastery over Windows registry.

Go to regedit and add this key: HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\Security\FileValidation 
Add: “EnableOnLoad”=dword:00000000

Source: https://social.technet.microsoft.com/Forums/lync/en-US/0fdf86d5-4cfb-480c-b672-6762f77112b9/completely-disable-protected-view-in-excel-2010?forum=excel

Saturday, September 24, 2016

Removing OPENJDK from CENTOS on VirtualBox


Step 1: Check the OpenJDK files using this command

rpm -qa | grep jdk

The output should be something like:








Step 2: Use the command:

sudo yum remove java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64

Continue using this command to remove the entries you get from the rpm command.

Step 3: Check whether any entries are left using the command used in Step 1.

As simple as that!! Isn't it!!

Express JS installation commands on NodeJS 4.5.0


I installed nodeJS 4.5.0.

Then struggled to install ExpressJS.

Later on, found the solution at the following site:

https://github.com/expressjs/express

Use the commands below (Windows 7 64 bit) in the command prompt:

1. npm install -g express-generator

This installs all the express dependencies and modules.

2. express expressjs && cd expressjs

This sets up the folder "express" to load all the needed files for installation.

3. npm install

This installs the expressjs package.

4. npm start

This starts the server.