Python Programming Python Code Samples



Filters


Ramya
Python program to find those numbers which are divisible by 7 and multiple of 5, between 1500 and 2700
Ramya | 1 year, 7 months
mylist = []
for i in range(1500,2700):
	if ((i%7==0) and (i%5==0)):
python
Get stats ( lines, words, char count ) of file in python
kishore_kumar | 2 years, 8 months
def file_stats(path):
    f = open(path, 'r')
    lines = f.readlines()
python
get sublist or sub matrix of numpy arrays
kishore_kumar | 2 years, 5 months
import numpy as np
random_arr = np.random.randint(1,50,9)
mat1 = ran.reshape(3,3)
python numpy
shuffle two lists and maintain order in python
kishore_kumar | 2 years, 3 months
import random

fruits = ['apples', 'mangoes', 'grapes', 'oranges']
python random
How to connect to presto using python and pyhive
kishore_kumar | 2 years
from pyhive import presto
cur = presto.connect('presto.yourhost.com',
                     '8889',
python pyhive presto
How to add markers and values to the line plot in python matplotlib
kishore_kumar | 2 years, 2 months
import matplotlib.pyplot as plt

t = ['12-03-18','12-04-18' , '12-05-18', '12-06-18', '12-07-18']
python matplotlib
How to parse cron string and get next schedule in python
kishore_kumar | 1 year, 5 months
# pip install croniter

from croniter import croniter
python croniter crontab
Read nth line in a file using python
kishore_kumar | 1 year, 3 months
file_ob = open('/path/to/file')
n = 4
for i, line in enumerate(file_ob):
python
generate random numbers matrix with numpy python
kishore_kumar | 2 years, 5 months
import numpy as np

random_arr = np.random.randint(1,50,9)
python numpy
Ramya
Python: Vending Machine
Ramya | 1 year, 7 months
class SodaMachine:
    def __init__(self,product,price):
        self.product=product
python >>>from <file_name> import <class_name> >>>shop=class_name("product",price) #Instantiate
python
Next