您的位置:首页 > 理论基础 > 数据结构算法

写了一个只有两个api的python库——Jerk Python——快速获得任何数据结构的近似整数

2014-04-27 16:57 381 查看



jerk

A simple python library to make python more python. Jerkpy is a simple and jerkful library to do some easy function more easily and more jerkfully.

Now he has only two APIs, welcome to develop him together.
Fork me on github.

His mind is just to pay attention to summing up some tips from our daily coding life and make it true to be a esier using funcitonal APIs, when we are in troubles, they maybe come in handy.


Installation

It is recommended to use pip to install jerkpy.
$ pip install jerk


Another way is to download it from this git or pypi, and then to install it manually via 
$
python setup.py install


Get started


import

how to import it,like this below:
from jerk import *


References


xlen

xlen( lst, start=0, step=1 )


In python, we can use "enumerate" to get both index and element of a list,

but for an obsessive-compulsive programmer he need an easy function to get only the index in an easy ways, which is just what "xlen" is doing.

Most of this api is the function combination of "xrange()" and "len()". (The result of "xrange()" is a generator which can supply the same need in function and so that is better than "range()" of which result is a list.)

[
lst
] is an argument at class of <"list"> to mean which index generator
will be output;

[
start
] can set the start number of the indexs. The default value of
this optional argument is 0.

[
step
] is an optional argument with the default value 1, which can set
the step of the indexs.

Example:
>>> from jerk import *>>>
>>> lst_test = ['k','u','f','c']
>>>
>>> for i in xlen( lst_test ):
... print i
...
>>> 0
>>> 1
>>> 2
>>> 3
>>>
>>> for i in xlen( lst_test,1 ):
... print i
...
>>> 1
>>> 2
>>> 3
>>> 4
>>>
>>> for i in xlen( lst_test,1,2 ):
... print i
...
>>> 1
>>> 3


xint

xint( a )


In python, if we want to get a nearest int number from a float number, we must use 
int(
round( object<"float"> ) )
. For coding less letters and brackets, 
xint(a)
 has
given into birth.

In addtion, if we want to make all the float numbers in a set or a dict or a list or a tuple to be transformed as int numbers, 
int(
round( object<"float"> ) )
 can't do the job because his object input must be only one float numbers. But 
xlen(a)
 can
do with all the things except a cyclic tree dict of course. 

Examples:
from jerk import *
a = 0.93
print "a = {},\nxint(a)={}\n".format( a, xint (a) )

a = [ 0.93, (291.1232332, 23.2323311) ]
print "a = {},\nxint(a)={}\n".format( a, xint (a) )

a = ( 0.93, 23.23, 54, [23.2, 3], '23' )
print "a = {},\nxint(a)={}\n".format( a, xint (a) )

a = { 0.93:239, \
'jerk.py':(0.93, 23.2234333, 54, [23.2, 3.23323, {2.2:-0.1}]), \
'23':-0.999 }
print "a = {},\nxint(a)={}\n".format( a, xint (a) )

>>> a = 0.93,
>>> xint(a)=1
>>>
>>> a = [0.93, (291.1232332, 23.2323311)],
>>> xint(a)=[1, (291, 23)]
>>>
>>> a = (0.93, 23.23, 54, [23.2, 3], '23'),
>>> xint(a)=(1, 23, 54, [23, 3], '23')
>>>
>>> a = {0.93: 239, 'jerk.py': (0.93, 23.2234333, 54, [23.2, 3.23323, {2.2: -0.1}]), '23': -0.999},
>>> xint(a)={1: 239, 'jerk.py': (1, 23, 54, [23, 3, {2: 0}]), '23': -1}


It only has two APIs now. Welcome to discuss which function def can make python esier and faster coding. Python is a very human language, which will be learned by every children in future.

目前有4个api了,不断发展中……提出你平时coding的习惯性需求,觉得哪些繁琐的东西应该简化,然后。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python jerk git pip
相关文章推荐