Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中的TypeError“int”_Python_Int - Fatal编程技术网

Python中的TypeError“int”

Python中的TypeError“int”,python,int,Python,Int,回溯: 回溯最近一次呼叫上次: liststr[aac]=aw[j] TypeError:“int”对象不可下标 这只是一个提取器,真正的代码 我不知道为什么会出现打字错误 该程序应提取列表中的数字,并将它们放在一个字符串中,如下所示: 名单[12,23,32] 致: 122332 您可以按如下方式重写函数: randsemiconclusion = [3234234, 234234, 23432] wordstring = "

回溯:

回溯最近一次呼叫上次:

liststr[aac]=aw[j]

TypeError:“int”对象不可下标

这只是一个提取器,真正的代码

我不知道为什么会出现打字错误

该程序应提取列表中的数字,并将它们放在一个字符串中,如下所示:

名单[12,23,32]

致:

122332


您可以按如下方式重写函数:

randsemiconclusion = [3234234, 234234, 23432]
wordstring = "                                                  "
liststr = list(wordstring)
for i in range(0, len(randsemiconclusion)):
    aw = randsemiconclusion[i]
    for j in range(0, 6):
        aac = int(i*7 + j+1)
        liststr[aac] = aw[j]
        wordstring = ''.join(liststr)
print("Wordstring -->  ", wordstring, "  <--")
另一种方法是使用列表理解:

def concatenate_list_data(list):
    result= ''
    for element in list:
        result += str(element)
    return result

my_result = concatenate_list_data([1, 5, 12, 2])   # leads to 15122

它在哪里给了你这个错误?如果让我猜的话,我会说aw是容器中的int。按照@DanielRoseman的要求,提供完整的回溯。randsemiconclusion可能是一个int值列表,这将使aw成为int。什么是typerandsemiconclusion和typeaw?如果它是int类型,那就是你的错误。它不是。它给你命名错误:名称“randsemiconclusion”没有定义。谢谢,这正是我要找的
to_join = [1, 5, 12, 2]
output = ''.join([str(i) for i in to_join])