scyther/test/tuples.py

52 lines
806 B
Python
Raw Normal View History

2004-10-14 19:18:01 +01:00
#!/usr/bin/python
#
# Given a number of input lines on std and an argument int, this program
# generates unordered tuples, e.g.:
#
# arg: 2
# in: a
# b
# c
# d
#
# out: a,b
# a,c
# a,d
# b,c
# b,d
# c,d
#
# This should make it clear what happens.
#
import sys
import string
2005-01-20 15:47:23 +00:00
import tuplesdo
2004-10-14 19:18:01 +01:00
# Retrieve the tuple width
2004-10-14 21:09:11 +01:00
tuplesize = int(sys.argv[1])
2004-10-14 19:18:01 +01:00
# Read stdin into list and count
list = []
loop = 1
while loop:
line = sys.stdin.readline()
if line != '':
# not the end of the input
line = string.strip(line)
if line != '':
# not a blank line
list.append(line)
else:
# end of the input
loop = 0
2005-01-20 15:47:23 +00:00
def tuplesPrint (l, n):
def f (resultlist):
print " ".join(resultlist)
2004-10-14 21:09:11 +01:00
2005-01-20 15:47:23 +00:00
tuplesdo.tuplesDo (f, l, n)
2004-10-14 21:09:11 +01:00
# Generate tuples...
2005-01-20 15:47:23 +00:00
tuplesPrint (list, tuplesize)
# Thanks for your attention