I'm trying to use a program in here to convert a copy and pasted list from excel into a list that I can manipulate using concatenate in Python. When I input the multiple column / row values I get a list that I'm having trouble manipulating. See the below example:
def detail_input():
try:
while True:
data=raw_input()
if not data: break
yield data
except KeyboardInterrupt:
return
123 56
321 42
987 24
userInput = list(detail_input())
[['123\t56'],['321\t42'],['987\t24']]
the group is 123 and their profile is 56
the group is 321 and their profile is 42
the group is 987 and their profile is 24
I've tried to use the below to remove the tab delimiter:
values = list(csv.reader(userInput, delimiter='\t'))
[['123','56'],['321','42'],['987','24']]
Please help if you have any ideas
you can do this.
values = list(csv.reader(userInput, delimiter='\t'))
# add the following line to print what you need.
[print("the group is {} and their profile is {}".format(each[0], each[1])) for each in values]
or something as easy as following.
values = list(csv.reader(userInput, delimiter='\t'))
for each in values:
group = each[0]
profile = each[1]
print("the group is {} and their profile is {}".format(group,profile))