我是Python新手.我正在尝试编写一个函数,将单独列表中的唯一值合并到一个列表中.我一直得到一个列表元组的结果.最后,我想从我的三个列表-a,b,c中得到一个唯一值列表.任何人都可以帮我一把吗?
def merge(*lists):
newlist = lists[:]
for x in lists:
if x not in newlist:
newlist.extend(x)
return newlist
a = [1,2,3,4]
b = [3,4,5,6]
c = [5,6,7,8]
print(merge(a,b,c))
Run Code Online (Sandbox Code Playgroud)
我得到了一个列表元组
([1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7, 8])
Run Code Online (Sandbox Code Playgroud) 我想文本字符串从形式变化file1来file01.我是python的新手,在尝试使用模式时无法弄清楚应该在'repl'位置进行什么.任何人都可以帮我一把吗?
text = 'file1 file2 file3'
x = re.sub(r'file[1-9]',r'file\0\w',text) #I'm not sure what should go in repl.
Run Code Online (Sandbox Code Playgroud)