Posts

Showing posts with the label Python Recursion Example

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

How to Write Recursive Function in Python Quickly

Image
Here's an example to write RECURSIVE function in Python. It acts like a loop that iterate within the function to perform some operation. Precisely, if you call the same function from function is called  recursive function .     Python recursive function Here are four rules a developer should know before writing recursive function in Python: There must be a key variable, which will be responsible for the termination of recursion. To determine the base value , which the key variable has to meet to reach the termination. To make sure the key variable must approach the base value in every recursive call. To make the recursive function terminate when the key variable reaches the base value. Python recursive example Here is an example python recursive function. # This program computes the factorial of a number using recursion #function definition def fact(n): "computes factorial using recursion" if n == 0:     return 1 else :     return n * fact(n - 1) # Function call num = i