TOP 10 INDIAN CITIES PAYING A FORTUNE FOR PYTHON DEVELOPERS IN 2022

Bengaluru, Karnataka

New Delhi, India

Gurgaon, Haryana

Hyderabad, Telangana

Pune, Maharashtra

Chennai, Tamil Nadu

Noida, Uttar Pradesh

Mumbai, Maharashtra

Kolkata, West Bengal

Lucknow, Uttar Pradesh


For more details 

Reservoir Sampling

import random

def printArray(stream,n):

for i in range(n):

print(stream[i],end=" ");

print();

def selectKItems(stream, n, k):

i=0;

reservoir = [0]*k;

for i in range(k):

reservoir[i] = stream[i];

while(i < n):

j = random.randrange(i+1);

if(j < k):

reservoir[j] = stream[i];

i+=1;

print("Following are k randomly selected items");

printArray(reservoir, k);

if __name__ == "__main__":

stream = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];

n = len(stream);

k = 5;

selectKItems(stream, n, k);


Program to print Lower triangular and Upper triangular matrix of an array

def lower(matrix, row, col):

for i in range(0, row):

for j in range(0, col):

if (i < j):

print("0", end = " ");

else:

print(matrix[i][j],

end = " " );

print(" ");

def upper(matrix, row, col):

for i in range(0, row):

for j in range(0, col):

if (i > j):

print("0", end = " ");

else:

print(matrix[i][j],

end = " " );

print(" ");

matrix = [[1, 2, 3],

[4, 5, 6],

[7, 8, 9]];

row = 3;

col = 3;

print("Lower triangular matrix: ");

lower(matrix, row, col);

print("Upper triangular matrix: ");

upper(matrix, row, col);


Find maximum value of Sum( i*arr[i]) with only rotations on given array allowed

def maxSum(arr):

arrSum = 0

currVal = 0

n = len(arr)

for i in range(0, n):

arrSum = arrSum + arr[i]

currVal = currVal + (i*arr[i])

maxVal = currVal

for j in range(1, n):

currVal = currVal + arrSum-n*arr[n-j]

if currVal > maxVal:

maxVal = currVal

return maxVal

if __name__ == '__main__':

arr = [10, 1, 2, 3, 4, 5, 6, 7, 8, 9]

print ("Max sum is: ", maxSum(arr))


Hexagons Turtle

import turtle

from random import randint

x = 20

y = 20

turtle.speed(100)

turtle.colormode(255)

def move(l, a):

                turtle.right(a)

                turtle.forward(l)

def hex():

        turtle.pendown()

        turtle.color( randint(0,255),randint(0,255),randint(0,255) )

        turtle.begin_fill()

        for i in range(6):

                move(x,-60)

        turtle.end_fill()

        turtle.penup()

turtle.penup()

for z in range (y):

        if z == 0:

                hex()

                move(x,-60)

                move(x,-60)

                move(x,-60)

                move(0,180)

        for i in range (6):

                move(0,60)

                for j in range (z+1):

                        hex()

                        move(x,-60)

                        move(x,60)

                move(-x,0)

        move(-x,60)

        move(x,-120)

        move(0,60)

turtle.exitonclick()