i want to only display the second column ,
this is my code
with open('try.txt', 'rb') as file1:
file1_data = dict(line.split(None, 2)[1:] for line in file1 if line.strip())
print file1_data
I only want to display the second column , but its also diplaying 3rd with it
This is the text file
E5 BAT One
E5 BALL Two
E5 CRICKET Three
Than i have to find the Bat
which is in second column of textfile1 in second
text file
?Bat03|Batsman
This is the goods of cricket
?Balt|Bowler
Both can be use by batsman and bowler
?Bat133|Swimmer
Swiming is the best exercise
So the Bat
which is in second column of textfile1
we goto second text file and find Bat and ignore value after |
, if Bat
in second text file before |
found than display it
with open('second.txt', 'rb') as file2, open('output.txt', 'wb') as outputfile:
output = csv.writer(outputfile, delimiter='|')
for line in file2:
if line[:1] == '?':
row = line.strip().split('|')
key = row[0][1:]
if key in file1_data:
output.writerow(row + [file1_data])
else:
outputfile.write(line)
Required output
?Bat03|Batsman
This is the goods of cricket
?Bat133|Swimmer
Swiming is the best exercise