I am the input from stdin
macys 100
sears 20
Boscov's 5
JCPenney 21
Kohl's 22
Others 16
This list will grow.
I want the output like below
macys sears Boscov's JCPenney Kohl's Others
100 20 5 21 22 16
I am the input from stdin
macys 100
sears 20
Boscov's 5
JCPenney 21
Kohl's 22
Others 16
This list will grow.
I want the output like below
macys sears Boscov's JCPenney Kohl's Others
100 20 5 21 22 16
as everyone has mentioned use cols = zip(*rows)
for example ...
some_text = """
macys 100
sears 20
Boscov's 5
JCPenney 21
Kohl's 22
Others 16
"""
#perhaps for you it will be some_text = sys.stdin.read()
#first convert it to a python list
some_list = some_text.splitlines()
#get rid of any empty lines
filtered_list = filter(None,some_list)
#split each line in half
rows_of_data = [line.split() for line in filtered_list]
#transpose it (turn it sideways)
headers,data = zip(*rows_of_data)
#print it out how you want
print "\n".join((" ".join(headers),
" ".join("%-*s"%(len(headers[i]),value) for i,value in enumerate(data))))
for line in stdin:
a = line.split()
list_a = a[0]
list_b = a[1]
print list_a
print list_b
datastring = """macys 100
sears 20
Boscov's 5
JCPenney 21
Kohl's 22
Others 16"""
converted = zip(*(line.split() for line in datastring.splitlines()))
converted
is list of tuples, each containing your items in given row.
You can use pandas
external library to easily manipulate data later:
import pandas as pd
dt = pd.DataFrame.from_records(converted[1:], columns=converted[0])
print dt
Output:
macys sears Boscov's JCPenney Kohl's Others
0 100 20 5 21 22 16