我是python新手,我很困惑。谁能向我解释从列表中制作集合的两种变体的区别?哪一个更正确?
a = ["Jake", "John", "Eric"]
b = ["John", "Jill"]
c = set([])
d = set([])
for i in range (len(a)):
c.add(a[i])
for y in range (len(b)):
d.add(b[y])
print c.difference(d)
import sets
e= sets.Set(a)
print e
f = sets.Set(b)
print f
print e.difference(f)
Outcome
set(['Jake', 'Eric'])
Set(['Jake', 'Eric'])
谢谢!