Monday, January 8, 2018

python list append, pop, unshift, shift, deque object insert appendleft clear copy extendleft

from collections import deque
a = [1,2,3,4,5]
a.append(6)
print a
print a.pop()
#['a'] = 'b'
a = ([10] + a + [11]) # Unshift / Push
print a
a = a[:6] # Shift / UnPush
print a, ';;;;;;;;;'
print a.pop(5)
del a[:3]
print a
print deque(a).popleft()



result::::::::::::::::::::::::::
PS D:\Projects\Python.Projects\maths> python main.py
[1, 2, 3, 4, 5, 6]
6 [10, 1, 2, 3, 4, 5, 11] [10, 1, 2, 3, 4, 5] ;;;;;;;;;
5
[3, 4] 3 PS D:\Projects\Python.Projects\maths>

python decimal,float,rmax,min,ound,sorted,sum,int

from decimal import *
getcontext().prec = 4
print Decimal(1) / Decimal(7)
formatted = Decimal('0.142857')
print formatted
#getcontext().prec = 28
print Decimal('0.1428571428571428571428571429')
print Decimal('NaN')
print (Decimal('-Infinity') == '-Infinity')

data = map(Decimal, '1.34 1.87 3.45 2.35 1.00 0.03 9.25'.split())
print max(data)
print min(data)
print sorted(data)
print sum(data)
#Decimal('19.29')
a,b,c,d = data[:4]
print str(a), str(b), str(c), str(d)
#'1.34 1.87 3.45 2.35'
print float(a)
#1.34
print round(a, 1) # round() first converts to binary floating point
#1.3
print int(a)
#1
print (a * 5)
#Decimal('6.70')
print (a * b)
#Decimal('2.5058')
print (c % a)
#Decimal('0.77')
print Decimal(9).sqrt()
#3
print Decimal(3).exp()
#20.09
print Decimal('10').log10()
#1

result:::::::::::::::::::::::::::::::::::

PS D:\Projects\Python.Projects\maths> python main.py 0.1429 0.142857 0.1428571428571428571428571429NaNFalse9.25 0.03 [Decimal('0.03'), Decimal('1.00'), Decimal('1.34'), Decimal('1.87'), Decimal('2.35'), Decimal('3.45'), Decimal('9.25')] 19.29 1.34 1.87 3.45 2.35 1.34 1.3 1 6.70 2.506 0.77320.09 1 PS D:\Projects\Python.Projects\maths>

python list Iterables, Generators, Yield

#
import time

start = time.clock()
mylist = [(x * x) for x in range(3000000)]
for i in mylist:
pass
stop = time.clock()
print stop-start


start = time.clock()
mygenerator = (x * x for x in range(3000000))
for i in mygenerator:
pass
stop = time.clock()
print stop-start


start = time.clock()
def createGenerator():
mylist = range(3000000)
for i in mylist:
yield i * i

mygenerator = createGenerator() # create a generator
#print(mygenerator) # mygenerator is an object!
for i in mygenerator:
pass
stop = time.clock()
print stop-start
#
#


value = raw_input()


def p_arr(str):
arr = str.split(',')
count = len(arr)
for item in arr:
print item
return count


print str(p_arr(value)) + ";;;"


result::::::::::::::
PS D:\Projects\Python.Projects\maths> python main.py 0.92048384 0.706350506667 0.705092266667 bor bor 1;;; PS D:\Projects\Python.Projects\maths>

Monday, October 2, 2017

how to get sequence int value by name in mysql

DELIMITER $$

CREATE FUNCTION `seqval` (`seq_name` VARCHAR(100))
RETURNS BIGINT(20) NOT DETERMINISTIC
BEGIN
    DECLARE cur_val bigint(20);

SELECT intval INTO cur_val FROM seqcontract
WHERE name = seq_name;

IF cur_val IS NULL THEN
SET cur_val = 1;

INSERT seqcontract(name, intval)
VALUES(seq_name, cur_val);
ELSE
SET cur_val = cur_val + 1;

UPDATE seqcontract
SET intval = cur_val
WHERE name = seq_name;
END IF;

RETURN cur_val;
END$$