|
发表于 2003-9-11 19:32:50
|
显示全部楼层
哈哈,开始用 perl 了,我也用 python
- $ cat comparray.py
- #!/usr/bin/env python
- a=('a', 'b', 'c', 'd', 'e')
- b=('a', 'f', 'c', 'g', 'w', 'e')
- print 'a:', a
- print 'b:', b
- print '两个数组相同的元素是:'
- for i in filter(lambda x: x in a, b):
- print i,
- print
- print '数组a中存在而数组b中不存在的元素是:'
- for i in filter(lambda x: x not in b, a):
- print i,
- print
- $ chmod +x comparray.py
- $ ./comparray.py
- a: ('a', 'b', 'c', 'd', 'e')
- b: ('a', 'f', 'c', 'g', 'w', 'e')
- 两个数组相同的元素是:
- a c e
- 数组a中存在而数组b中不存在的元素是:
- b d
复制代码 |
|