Posts

Featured Post

SQL Interview Success: Unlocking the Top 5 Frequently Asked Queries

Image
 Here are the five top commonly asked SQL queries in the interviews. These you can expect in Data Analyst, or, Data Engineer interviews. Top SQL Queries for Interviews 01. Joins The commonly asked question pertains to providing two tables, determining the number of rows that will return on various join types, and the resultant. Table1 -------- id ---- 1 1 2 3 Table2 -------- id ---- 1 3 1 NULL Output ------- Inner join --------------- 5 rows will return The result will be: =============== 1  1 1   1 1   1 1    1 3    3 02. Substring and Concat Here, we need to write an SQL query to make the upper case of the first letter and the small case of the remaining letter. Table1 ------ ename ===== raJu venKat kRIshna Solution: ========== SELECT CONCAT(UPPER(SUBSTRING(name, 1, 1)), LOWER(SUBSTRING(name, 2))) AS capitalized_name FROM Table1; 03. Case statement SQL Query ========= SELECT Code1, Code2,      CASE         WHEN Code1 = 'A' AND Code2 = 'AA' THEN "A" | "A

Python Delete Duplicates in List Faster Way

Image
Removing duplicates in List simplified using SET method. It's a simple method. Just you need SET and Print to remove duplicates. Removing duplicates is common in Data science projects. What is list A list is a collection of elements. The elements can be duplicates or non-duplicates. Today's task is to remove duplicate elements in the List. Faster way to remove list duplicates Create a List Use SET Print the result List with duplicates my_list = ['The', 'unanimous', 'Declaration', 'of', 'the', 'thirteen','united', 'States', 'of', 'America,', 'When', 'in', 'the', 'Course', 'of', 'human'] Apply set method >>> non_dupes = set(my_list) Print Final list >>> print(non_dupes) Here, if you observe, there are no duplicates. The duplicates are now removed. It displays only non-duplicate values.  Here 'the' is a duplicate value. That'

How to Fix datetime Import Error in Python Quickly

Image
Here's a quick resolution for import datetime Python error . The reason is your .py python script name and datetime  are the same. I'll show you how this error happens and its resolution.   Here's the Resolution for ImportError I've created a script called 'datetime.py.' to check whether the minute value is 'odd' or not. During the import of my python script, I got the import error cannot import name datetime. My Script: datetime.py My script's intention is to find whether the minute value is odd or not. Python Logic from datetime import datetime odds = [ 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 , 17 , 19 , 21 , 23 , 25 , 27 , 29 , 31 , 33 , 35 , 37 , 39 , 41 , 43 , 45 , 47 , 49 , 51 , 53 , 55 , 57 , 59 ] right_this_minute = datetime.today().minute if right_this_minute in odds: print ( "This minute seems a little odd." ) else : print ( "Not an odd minute." ) ImportError I have imported my datetime.py from Linux. It gives an error

How to Count Vowels in Input Quickly

Image
Here you'll know how python counts characters in the input. This is an interview question asked recently. How to Count Vowels in Input String Below is the Interview Question Vowels = ('aeiou') You need to check any vowels are present in the input string. Vowels means 'a', 'e', 'i', 'o', 'u'. The below function checks each character of input and compares it with the Vowels. 3 Steps to Count Vowels in Input You can achieve this in three steps. 1. Create a function called 'my_vowel' (the name up to you) 2. Use Set & Intersection Method 3. Run the function 1. Created 'my_vowel' Function #!usr/bin/python #This function finds vowel counts #welcome to my function """ Optional description """ def my_vowel (a): vowels = set ( 'aeiou' ) a_1 = vowels . intersection( set (a)) # initialized the dictionary found = { 'a' : 0 , 'e' : 0 , 'i' : 0 ,

Python - How to Lookup Dictionary by Key

Image
Here's Python Dictionary that explained how to lookup it using Key. Dictionary in Python is Key/Value pair. It's different from the list. The basic rule to identify; is enclosed in flower brackets ({}). Here's a demo about lookup and how to test it.  Dictionary = { 'key' : 'value', 'key: value'  }   IN THIS PAGE Python Dictionary Python Lookup How to check Lookup working or not Dictionary Example my_dict = {'name' : 'srini' , 'salary' : '100000', 'skills' : 'python' } Here, 'name' is the label. Then, : Then, 'srini' -> Value Explanation Data is enclosed in flower brackets It's an unordered list You can manipulate data (mutable) You can access the value of a particular key. So, in Python, it's called a Lookup. It's one of the best interview questions. You May Also Like :  Python Dictionary Vs List With Examples Lookup Dictionary by Key Python Lookup (a.k.a Dictionary). You

How to Use List Function in Python

Image
Here's is an answer to calculate the length of the repeated lists. LIST is a principle data type in Python that holds a list of values. Usually strings. List() Function the Real Usage You can do various operations with Lists. The best examples are REPEAT, APPEND, INSERT, EXTEND, COUNT. Still more you can do. Note: This question is from a test recently held by an HR company. HR firms usually ask to take an online test to filter the job-seekers. IN THIS PAGE 1. Question 2. How to Find Length Interview Question  The '* 2' says times the list is repeated. In this question, they have given '2' times. my_list = ['srini', 'seetha', 'rao'] b = len(list(list(list(list(list(my_list*2)))))) Print (b) Select Answer 1. 5 2. 6 3. 7 4. None Explanation: In the first step, the '*' says, you repeated the List two times. It confuses the test-taker since they have given multiple functions of the list(). How to get Length You can code the way I did. So

How to Find Max and Min Quickly in Python List

Image
Here's logic to find Max and Min values in a List. Without using built-in Max() and Min () functions you can find Max and Min values in a List. For that matter, you need to write a user-defined function. This post is all about how to write it and run. Finding Max and Min in List You can achieve this by writing a user-defined function. Here's useful logic and steps to write it precisely. IN THIS PAGE Write a Function Execute Function Get the result Write Function You can write an user-defined function to get MAX and MIN values. In this function, I am using the max(), min() built-in functions. The other variables you can use as you wish. Below is the my actual logic. Sample Code def findmaxmin (data): ax = max (data) by = min (data) return (x,y) data = ( 109 , 98 , 88 , 7 ) (maximum, minimum) = findmaxmin (data) print ( "Maximum Marks = " , maximum) print ( "Minimum Marks = " , minimum) Created a Script Using vim editor Here as the first step, I

How to Write Class Object in Ubuntu Python

Image
Python supports object-oriented programming, which makes python powerful. Creating class in Ubuntu python explained. You can use it in different ways by assigning it to an object. Doing all these are explained in the below steps.   Writing Class in Python in 3 Steps Python code Write the code in script Execute script Writing Class in Python Below sample code my give indentation errors. However, I have corrected the code in the actual script. class Employee: """Base class""" empCount = 0 def __init__(self, name, salary): self.name = name self.salary = salary Employee.empCount += 1 # can also be written as Employee.empCount = Employee.empCount + 1 def displayEmployee(self): # function is defined here print "Name : ", self.name, ", Salary: ", self.salary # "emp1 is the first object of Employee class" emp1 = Employee("Akhil", 2000) # "emp2 is the second object of Employee class" emp2 = Employee(&quo