Posts

Dictionary in Python

# how to create blank dictionary dictionary = {} print(dictionary) # declare dictionary with key and value dictionary = {"fname": "avni","mname":"singh","lname":"rathor"} print(dictionary) # accessing key and value from dictionary for key in dictionary:     print(key)     print(dictionary[key]) # accessing key and value with items method for key,value in dictionary.items():     print(key,value) #  value can also be fetched from get method print(dictionary["fname"]) print(dictionary.get("fname")) # now will add key and value in dictionary . dictionary["age"] = "31" print(dictionary) # now removing item fname  from dictionary dictionary.pop("fname") print(dictionary) # del keyword can also be used del del dictionary["lname"] print(dictionary) # can clear dictionary with clear function dictionary.clear() print(dictionary) # dict constructior

list in python

# declaring a list list_t = [ "my" , "name" , "is" , "abhishek" ] print (list_t) # accessing first list item print (list_t[ 0 ]) # accessing all item of list for x in list_t: print (x) # inserting item at position in list . list_t.insert( 0 , "hello" ) print (list_t) # extending a list lastname = [ "rathor" ] list_t.extend(lastname) print (list_t) # removing item from list list_t.pop( 0 ) print (list_t) list_t.remove( "rathor" ) print (list_t) # index of item in list print (list_t.index( 'name' )) # sorting an index list_t.sort() print (list_t) # reverse is also possible in index list_t.reverse() print (list_t) # constructing a list with constructor list2 = list (( "abhishek" , "pratap" , "singh" , "rathor" )) print (list2) # tuple and list both behave same except tuple are unchangeable and ordered collection # so inserting and removing

Triggers in MySQL

Image
Trigger MySQL: Trigger can be used in two ways with before and after with Delete ,insert and update command .Let me show you a example of before update   . I have created two table employee and employee_audit . employee table is table where my raw data will be stored and employee_audit table is table where to store data after changes or can say trigger execution . Table structure of employee and employee_audit table : CREATE TABLE   `test`.`employee` (   `id` int(11) NOT NULL AUTO_INCREMENT,   `name` varchar(20) DEFAULT NULL,   `lstname` varchar(10) DEFAULT NULL,   PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1; CREATE TABLE   `test`.`employee_audit` ( `id` int(11) NOT NULL AUTO_INCREMENT,   `name` varchar(20) DEFAULT NULL,   `lstname` varchar(20) DEFAULT NULL,   `action` varchar(50) DEFAULT NULL,   `upd_datetime` datetime DEFAULT NULL,   `newname` varchar(20) DEFAULT NULL,   `newlstname` varchar(20) DEFAULT NULL,   PRIMARY KEY (`

Machine Learning : Cross Validation Technique

Cross validation is one way to avoid over fitting of data in machine learning . Cross validation works in such way : 1st Way : One Round Cross Validation :   in this data is divided into  50-50 portion ,one portion is for test set , one portion is validation of model that is prepared with the help of 50% of data . Leave one out cross validation(LOOCV)  : In this ,we leave one data set for cross validation  and rest data set for use for training of model . k-fold cross validation : In this k data set are used to trained  the model ,while k-1 are using for validate or test  the model .

Machine Learning 1

Image
Machine Learning : if you talk about artificial intelligence , then Machine learning is one way to feed artificial intelligence to obtain intelligence in making decision . Machine learning use statistics ,algebra ,probability and other mathematical related algorithm. so there is always question ,what we should  do to   use machine learning in daily life ,because if any where you are working ,you can use  AI ,but for that you should know Machine Learning ,Deep learning and Python programming and logic to fit all these in a pattern . so first we will go with machine learning basic concept : machine learning use  training data for making algorithm to predict future decision or daily routine decision . enough past data is feed into training set to make algorithm. Machine Learning information can be divided into following categories : 1: Unsupervised learning . 2: Supervised learning  3: Semi Supervised learning    Unsupervised learning  : When learning data contains o

Logging in Python .

Python logging is as much important for python as flavours in Ice Cream , lies in politics and life without goal .without flavour ice cream means ,it may be tasty for you but not for others ,so  a programme should be like that it should be understandable by others .Logging is used for log purpose of a programme ,what actually it is doing .lies in politics means you can not grow your code without logging otherwise ,it is very difficult to track your programme . So before further moving we can see .where logging can be used . 1: Displaying a information of  programme . 2: Issuing a warning . 3: Catching  a error . 4: Catching Critical information . How we can  achieve by python logging: So for achieving we need to know  ,level in python ,mostly 5 type of level are used in python DEBUG,INFO,WARNING ,ERROR and CRITICAL .let's elaborate what actually each level means in python . DEBUG : Debug we used for diagnostic purpose or detailed information . INFO     : Programme is w

Python : Working With File and Directory

Q: How to list all files From a directory ? Ans : You Can do it any many way ,  mentioned  are  some way 1st way: import os for file in os.listdir("C:/ra"): if file.endswith(".gz"): print(os.path.join("C:/ra", file)) # 2nd way: import glob, os os.chdir("C:/ra") for file in glob.glob("*.gz"): print(file) # 3rd way: import os for root, dirs, files in os.walk("C:/ra"): for file in files: if file.endswith(".gz"): print(os.path.join(root, file)) Q: How to unzip gz file into normal . Ans : import shutil with open('C:/xyz.xml', 'rb') as f_in, gzip.open('C:/xyz.xml.gz', 'wb') as f_out: shutil.copyfileobj(f_in, f_out)