I'm sort of new to Python and I have tried to search for a solution to this.
I have two files. One with 1.573.553 integers like:
2990003032
2390058393
2390059146
2320205495
2320205497
2320206150
2320206151
2320206152
2320206153
2320206154
...
And another file with 1.645.637 lines, a string and an integer separated by ';' like:
AS An1;4601094657
AS An1;4601094658
AS An1;4601127943
AS An1;4601127986
AS An2;4601127987
AS An2;4601127988
AS An3;4601127993
AS An3;4601127994
AS An3;4601127996
AS An3;4601127997
...
Now I want to create an array using the first file values. Then I want to create a second array using the second file's values as the key and the strings as value.
All this to iterate through the first array and checking if the integer exist as key in the second array and if so write the value and the key into a new file separated by ';'. Because grep would take forever.
My question is how I create the second array, where I iterate through each line splitting on ';' and using the second part as key in the array and the first part as value.
Any help is greatly appreciated and I guess the solution is simple once I see it.
You can implement like
file: test.txt
AS An1;4601094657
AS An1;4601094658
AS An1;4601127943
AS An1;4601127986
AS An2;4601127987
AS An2;4601127988
AS An3;4601127993
AS An3;4601127994
AS An3;4601127996
AS An3;4601127997
Code:
with open("test.txt") as fp:
lines = fp.readlines()
print dict((x.split(';')[1][:-1], x.split(';')[0]) for x in lines)