写了一个只有两个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的习惯性需求,觉得哪些繁琐的东西应该简化,然后。。。
相关文章推荐
- 给定一个整数数组,两个数字的返回索引将它们加到一个特定的目标中。 您可以假设每个输入都只有一个解决方案,并且您可能不会两次使用相同的元素。
- 今天学习时突然联想到这样一个有趣但无用的问题:利用C语言(不能是其他语言)求两个整数的较大/小值-----要求不用if、三目?、switch、循环、数组、加减乘除求余、位运算符以及任何库函数
- 设计一个数据结构,包含两个函数,1.插入一个数字,2.获得中数
- mac安全与隐私只有两个选项,少了一个任何来源
- 编写一个函数比较两个整数大小,但不能使用任何比较操作符
- Java得到一个整数的绝对值,不使用任何判断和比较语句,包括API.
- Java得到一个整数的绝对值,不使用任何判断和比较语句,包括API
- 一个无序自然数序列有N个自然数,快速找到二者之和为M的两个整数并输出
- 设计一个数据结构,其中包含两个函数,1.插入一个数字,2.获得中数。并估计时间复杂度。
- 如何快速找到一个整数的两个最接近的因子
- 每天一道LeetCode-----一个整数序列,每个元素出现两次,只有一个(两个)出现一次,找到这个(这两个)元素
- python-反转一个只有3位数的整数。
- Java得到一个整数的绝对值,不使用任何判断和比较语句,包括API
- Java得到一个整数的绝对值,不使用任何判断和比较语句,包括API.
- 一个无序整数数组中找到最长连续序列(Longest Consecutive Sequence)和两个元素使得相差最小
- 通过百度提供API接口获得同一个城市两个位置交通路线
- python(dict字典相关知识以及小例子:生成一个列表,存放100个随机整数,找出出现次数最多的数字)
- 随机产生两组整数,每组整数中元素互不相同,这两组数按值递增有序。设计程序,将这两组数合并成按值递减有序的一组数,要求合并的新的一组数中,相同的元素只有一个。
- 推出两个python工具包,一个rtsp-server工具包,一个uvc工具包