猫史档案馆


【Python作品分享】并集【教程贴】

用户:纳米病毒纳米病毒查看:2 回复:2 评论:2 创建时间:2020-01-05T20:18:12


【作品展示】

center_image

 

【作品介绍】

输入两个集合(“{}”不用输入),然后输出两个集合进行并集运算后的集合。

 

【作品源代码】

def A_U_B(a,b):
    c = []
    for i in a:
        c.append(i)
    for i in b:
        c.append(i)
    d = []
    for i in c:
        if not i in d:
            d.append(i)
    return d

def output(out):
    print('{',end = '')
    for i in range(0,len(out)-1):
        print(out[i],end = ',')
    print(out[-1],end = '')
    print('}',end = '')
    
Input_1 = input('输入一串集合(列举法):').split()
Input_2 = input('输入一串集合(列举法):').split()
print('开始进行集合合并')
output(A_U_B(Input_1,Input_2))

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
秋葵秋葵

可是python 以及有 set(集合)了

点赞0


评论


编码已破译编码已破译

{1,2,3}|{2,3,4} ->{1,2,3,4}
#python的集合可以这样并集

点赞0


评论