Featured Post

SQL Query: 3 Methods for Calculating Cumulative SUM

SQL provides various constructs for calculating cumulative sums, offering flexibility and efficiency in data analysis. In this article, we explore three distinct SQL queries that facilitate the computation of cumulative sums. Each query leverages different SQL constructs to achieve the desired outcome, catering to diverse analytical needs and preferences. Using Window Functions (e.g., PostgreSQL, SQL Server, Oracle) SELECT id, value, SUM(value) OVER (ORDER BY id) AS cumulative_sum  FROM your_table; This query uses the SUM() window function with the OVER clause to calculate the cumulative sum of the value column ordered by the id column. Using Subqueries (e.g., MySQL, SQLite): SELECT t1.id, t1.value, SUM(t2.value) AS cumulative_sum FROM your_table t1 JOIN your_table t2 ON t1.id >= t2.id GROUP BY t1.id, t1.value ORDER BY t1.id; This query uses a self-join to calculate the cumulative sum. It joins the table with itself, matching rows where the id in the first table is greater than or

Python Advanced For Loop With Example

Basically, For Loop reads input value and stores in a variable. So For Loop in Python needs two arguments. The two arguments are VARIABLE and IN. So far so good. The next part of the article and examples well explained how it works and how to get the index for each input supplied.

for loops in python

In Python, for loop list and count are related to the same logic. In the below example, I have taken one array and I counted using for loop, the number of elements in the input list.

For loop Syntax

for count in[1, 2, 3]: 

The first step, How the above syntax works are what I want to share with you. The 'in' represents input array for Python for loop. That means the for loop works 3 times in Python. It displays only 3 times. The third step is just to give 'yes', which will multiply with 'count' for 3 times.

This is the whole story of for loop in Python. In the second step, print just displays values of input that stored in the for loop variable of 'count'.

The 'count' gets values one by one from for loop input array. When you used the Shell to enter a loop, there was a reason that the interpreter waited to respond until after you entered an empty line: The interpreter did not know how long the loop block was going to be! The empty line is a signal to the interpreter that you are done with the loop block.

The index in For loop 

A small example is given to get index and value from for loop.
#Get index using for loop
#You will get index and value
mylist=[1, 2, 3]: 
for idx, val in enumerate(mylist):
    print(idx, val)

Video Tutorial

I have created a small video so that you can play quickly and check how for loop works in Python.
Also, read


Popular posts from this blog

How to Fix datetime Import Error in Python Quickly

Explained Ideal Structure of Python Class

How to Check Kafka Available Brokers