示例#1
0
def decrypt(encrypted_text, n_times):
    """
    This function decrypt string puted as an argument.
    It restore the oryginal array
    and to do so it iter itself n times through while loop
    """
    if n_times <= 0:
        l_enc = encrypted_text
    else:
        loop = 0
        j_list_tuple = []
        l_enc = list(encrypted_text)
        while loop < n_times:
            len_enc = len(l_enc)
            beg = l_enc[math.floor((len_enc / 2)):]
            end = l_enc[:math.floor((len_enc / 2))]
            zip_enc = tuple(zl(beg, end, fillvalue=""))
            loop += 1
            for elem in zip_enc:
                j_tuple = "".join(elem)
                j_list_tuple.append(j_tuple)
                l_enc = "".join(list("".join(j_list_tuple)))
            j_list_tuple = []

    return l_enc
示例#2
0
def dir_py(obj, colwise=False, cols=4, prn=True):
    """The non-numpy version of dirr
    """
    from itertools import zip_longest as zl
    a = dir(obj)
    w = max([len(i) for i in a])
    frmt = (("{{!s:<{}}} ".format(w))) * cols
    csze = len(a) / cols  # split it
    csze = int(csze) + (csze % 1 > 0)
    if colwise:
        a_0 = [a[i:i + csze] for i in range(0, len(a), csze)]
        a_0 = list(zl(*a_0, fillvalue=""))
    else:
        a_0 = [a[i:i + cols] for i in range(0, len(a), cols)]
    if hasattr(obj, '__name__'):
        args = ["-" * 70, obj.__name__, obj]
    else:
        args = ["-" * 70, type(obj), "py version"]
    txt_out = "\n{}\n| dir({}) ...\n|    {}\n-------".format(*args)
    cnt = 0
    for i in a_0:
        cnt += 1
        txt = "\n  ({:>03.0f})  ".format(cnt)
        frmt = (("{{!s:<{}}} ".format(w))) * len(i)
        txt += frmt.format(*i)
        txt_out += txt
    if prn:
        print(txt_out)
    else:
        return txt_out
示例#3
0
def write_tables(taxa_dict):
    """
    Write the taxa that have been classified by different methods, and the overlap between the two
    to tab-separated text files.
    input: dictionary with taxa per rank per method
    output: tab-separated files (e.g. {sample}.Jovian-CAT.comparison.species.tsv)
    """
    for rank in RANKS:
        overlap = sorted(
            list(
                set(taxa_dict["%s_jovian" % rank])
                & set(taxa_dict["%s_cat" % rank])))
        #overlap thanks to Mark Byers: https://stackoverflow.com/a/3697438
        unique_jovian = sorted(
            list(
                set(taxa_dict["%s_jovian" % rank]) -
                set(taxa_dict["%s_cat" % rank])))
        unique_cat = sorted(
            list(
                set(taxa_dict["%s_cat" % rank]) -
                set(taxa_dict["%s_jovian" % rank])))
        #uniques thanks to Javed: https://stackoverflow.com/a/47264446

        with open("%s%s.tsv" % (snakemake.params["list_prefix"], rank),
                  'w') as outfile:
            outfile.write("Overlap\tJovian\tCAT\n")
            for a, b, c in zl(overlap, unique_jovian, unique_cat,
                              fillvalue=''):
                outfile.write("{0:20s}\t{1:20s}\t{2:20s}\n".format(a, b, c))

    return (None)
示例#4
0
def dir_py(obj, colwise=False, cols=4, prn=True):
    """The non-numpy version of dirr
    """
    from itertools import zip_longest as zl
    a = dir(obj)
    w = max([len(i) for i in a])
    frmt = (("{{!s:<{}}} ".format(w)))*cols
    csze = len(a) / cols  # split it
    csze = int(csze) + (csze % 1 > 0)
    if colwise:
        a_0 = [a[i: i+csze] for i in range(0, len(a), csze)]
        a_0 = list(zl(*a_0, fillvalue=""))
    else:
        a_0 = [a[i: i+cols] for i in range(0, len(a), cols)]
    if hasattr(obj, '__name__'):
        args = ["-"*70, obj.__name__, obj]
    else:
        args = ["-"*70, type(obj), "py version"]
    txt_out = "\n{}\n| dir({}) ...\n|    {}\n-------".format(*args)
    cnt = 0
    for i in a_0:
        cnt += 1
        txt = "\n  ({:>03.0f})  ".format(cnt)
        frmt = (("{{!s:<{}}} ".format(w)))*len(i)
        txt += frmt.format(*i)
        txt_out += txt
    if prn:
        print(txt_out)
    else:
        return txt_out
def insert_operators(r, s):
    t = []
    a = []

    for i in pro((' + ', ' - ', ''), repeat=len(r) - 1):
        t.append(i)
        a.append(''.join(
            (''.join(map(str, l))) for l in list(zl(r, i, fillvalue=''))))

    for i in a:
        if eval(i) == s:
            return i + ' = ' + str(s)
示例#6
0
"""class add:
    def __init__(self, a, b):
        print(a + b)


add(2, 3)
print ("Tanvir")"""
"""import calendar
print(calendar.month(5000, 5))
print(calendar.calendar(2020))"""
'''import sys
import os

try:
    a, b = 3, 0
    print(a / b)
except:
    print(sys.exc_info()[1])

print(os.path.dirname("project01"))'''
from itertools import zip_longest as zl
print(set(zl([1, 2], [3, 4, 5])))
print(chr(65))
print(ord("A"))
def vertical_strings(strings):
    iters = [iter(s) for s in strings]
    concat = ''.join
    return '\n'.join(map(concat, zl(*iters, fillvalue='')))