zoukankan      html  css  js  c++  java
  • python 一些乱七八糟的东西

    import random
    import os
    import sys
    import re
    
    class _is:
        def __init__(self,reg):
            self.cr=re.compile(reg)
        def __call__(self,string):
            return self.cr.fullmatch(string)!=None
    
    def ecall(x):
        if hasattr(x,"__call__"):
            return x()
        else:
            return x
    
    def ifcc(cond,c1,c2):
        if cond:
            return ecall(c1)
        else:
            return ecall(c2)
    
    def iff(c,c2):
        if c==None:
            return c2
        else:
            return c
    
    ## System random state manipulator
    # A redefined reseeding function seeding with a large amount of entropy
    def reseed(a=None,bytec=32):
        if a==None:
            a=os.urandom(bytec)
        random.seed(a)
    # aliases
    gstate=lambda:random.getstate()
    sstate=lambda x:random.setstate(x)
    gbits =lambda x:random.getrandbits(x)
    choose=lambda x:random.choice(x)
    
    ## Mathematical
    import math
    import numbert as nt
    
    ##classes
    class udist:
        def __init__(self,l,u):
            self.l=l
            self.u=u
        def __call__(self):
            r=random.randint(self.l,self.u)
            return r
    
    class rdist:
        def __init__(self,l,u):
            self.l=l
            self.u=u
            self.avail=set()
        def __call__(self,l=None,u=None,avail=None):
            l=iff(l,self.l)
            u=iff(u,self.u)
            avail=iff(avail,self.avail)
            # print(l,u,avail)
            r=random.randint(l,u)
            while r in avail:
                r=random.randint(l,u)
            avail.add(r)
            return r
    
    ## utilities
    serialize=lambda x,sep=' ',processor=str:sep.join(map(lambda x:processor(ecall(x)),x))
    sfloat=lambda prec=6:lambda x,y="%%.%df"%prec:y%x
    loop=lambda x,y:[y(i) for i in range(x)]
    uloop=lambda x,y:[ecall(y) for i in range(x)]
    isint=_is('[0-9]+')
    def choo(rndfn,cond):
        q=rndfn()
        while not cond(q):
            q=rndfn()
        return q
    
    args=list(map(lambda x:ifcc(isint(x),lambda:int(x),x),sys.argv[1:]))
    compose=lambda x,y:lambda:x(ecall(y))
    cr=lambda x,y:y()
    cct=lambda x,y:lambda:cr(x(),y)
    # Repl test
    def Repl(gl,lc):
        s=input()
        while s!='end':
            ret=eval(s,gl,lc)
            print(">",ret)
            s=input()
    
    
    
  • 相关阅读:
    1.ok6410移植bootloader,移植u-boot,学习u-boot命令
    ok6410按键中断编程,linux按键裸机
    四. jenkins部署springboot项目(1)--window环境
    一.jenkins安装(windows环境)
    oracle服务端导出/导入方式expdp/impdp
    linux 日志文件查看
    linux kafka进程挂了 自动重启
    kafka manager遇到的一些问题
    if条件语句
    shell脚本的条件测试与比较
  • 原文地址:https://www.cnblogs.com/tmzbot/p/9258863.html
Copyright © 2011-2022 走看看