Python 3.x 从数字开始做两个列表

Python 3.x 从数字开始做两个列表,python-3.x,Python 3.x,我有个问题。我解释:我有一个数字,比如273745328191,第二个数字,比如3。我们知道len(273745328191)可以除以3。我想用以下方式创建两个列表: A=[2+7+3,3+2+8] B=[7+4+5,1+9+1] 适用于273745328191和2 A=[2+7,4+5,8+1] B=[3+7,3+2,9+1] 我们假设输入数据使得列表A和B的长度相同 如何编写函数来实现这一点?我不知道这是可能的,因为我是初学者。好的,这里有一个函数,可以显示你想要的,我不知道你是否需要显

我有个问题。我解释:我有一个数字,比如273745328191,第二个数字,比如3。我们知道len(273745328191)可以除以3。我想用以下方式创建两个列表:

A=[2+7+3,3+2+8]
B=[7+4+5,1+9+1]
适用于273745328191和2

A=[2+7,4+5,8+1]
B=[3+7,3+2,9+1]
我们假设输入数据使得列表A和B的长度相同


如何编写函数来实现这一点?我不知道这是可能的,因为我是初学者。

好的,这里有一个函数,可以显示你想要的,我不知道你是否需要显示+符号,但我希望我的代码可以帮助你理解这是如何工作的

def split_my_list(mysequence, divider):
    mysequence = str(mysequence)
    split_list = ([mysequence[index-divider: index] for index, value in enumerate(mysequence, 1) if index%divider==0])

    A = [value for index, value in enumerate(split_list) if index%2 ==0]
    B = [value for index, value in enumerate(split_list) if index%2 !=0] 
    print('separated A', A)
    print('separated B', B)

    A = [list(map(int, i)) for i in A]
    B = [list(map(int, i)) for i in B]
    print('mapped A with integers', A)
    print('mapped B with integers', B)

    A = [sum(i) for i in A]
    B = [sum(i) for i in B]

    print("summed values in A", A)
    print("summed values in B", B)


split_my_list(273745328191, 2)
print('='*8)
split_my_list(273745328191, 3)
输出

separated A ['27', '45', '81']
separated B ['37', '32', '91']
mapped A with integers [[2, 7], [4, 5], [8, 1]]
mapped B with integers [[3, 7], [3, 2], [9, 1]]
summed values in A [9, 9, 9]
summed values in B [10, 5, 10]
========
separated A ['273', '191']
separated B ['745', '328']
mapped A with integers [[2, 7, 3], [1, 9, 1]]
mapped B with integers [[7, 4, 5], [3, 2, 8]]
summed values in A [12, 11]
summed values in B [16, 13]
重要参考资料


关于123456789和123456789和123456789和123456789,我们假设输入数据是这样的,即列表A和B的长度对于3列(数字)=6或12或18是相同的……对于5对于3列(数字)=10或20或30……如果你在掷六面骰子,你的程序究竟为什么使用273745328191这样大的数字?将骰子滚动序列转换成这样的单个数字需要额外的工作,而将它们转换成这样的数字并不是一种有用的形式。