def multpoly(entryList):
x = entryList.index(0)
if type(x) is list:
print("list")
if type(x) is str:
combined_str = ""
for x in entryList:
combined_str += x
return combined_str
print(multpoly(["1", "2", "3"]))
答案 0 :(得分:0)
def multipoly(l): #l not list
x = l[0]
if isinstance(x, str):
return ''.join(l)
elif isinstance(x, list):
return [a for sublist in l for a in sublist]
else:
raise ValueError("Not a list of strings or list of lists")
使用isinstance
检查类型。不要使用已经有意义的名称,例如list
。