Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: help!!
|
Posted: Oct 29, 2003 10:18 AM
|
|
Here is a sample in Python. (I haven't tried it with Jython, but that should work too (I think it does the list comprehensions and stuff, but I'm not certain...), if you insist on using Java somehow.) You can download Python from http://www.Python.org, if you haven't already got it.
# Read a text file, if it was specified (otherwise, use sample): import os,sys if len(sys.argv) > 1 and os.path.isfile(sys.argv[1]): lines = [l.strip() for l in file(sys.argv[1]).readlines()] else: sampleInput = """ No of visits to location ( 1,1) >> [0, 2, 4, 28, 2] No of visits to location ( 1,2) >> [0, 4, 8, 9] No of visits to location ( 1,3) >> [0, 82, 2] No of visits to location ( 1,4) >> [0, 7, 10] No of visits to location ( 1,5) >> [0, 17] No of visits to location ( 1,6) >> [0, 1, 2, 3, 4, 5, 6, 7]""" lines = [l.strip() for l in sampleInput.splitlines()]
stuff={} for l in lines: key,values = l[l.find('('):].split('>>') stuff[eval(key)] = eval(values)
keys = stuff.keys() keys.sort()
# Determine which point has longest list of values: longest = max( [len(stuff[k]) for k in stuff] )
elementFormat = '%-6s' # You might tweak this if you have bigger values.
# Print headers: for k in keys: print elementFormat % str(k), print
# Print data: for i in range(longest): for k in keys: if len(stuff[k]) > i: value = str(stuff[k][i]) else: value = '' print elementFormat % value, print
|
|