I am processing a text file whose columns are separated by tabs .I want to get all the unique values of the first column.
Text Input e.g:
"a\t\xxx\t..\zzz\n
a\t\xxx\t....\n
b\t\xxx\t.....\n
b\t\xxx\t.....\n
c\t\xxx\t.....\n"
So in this case i would like to get an array: uniques=["a","b","c"]
Code:
def getData(fin):
input = open(fin, 'r',encoding='utf-16')
headers=input.readline().split()
lines=input.readlines()[1:]
uniques=[(lambda line: itertools.takewhile(lambda char: char!='\t',line))for line in lines]
Instead of the desired values i get a list of :
<function getData.<locals>.<listcomp>.<lambda> at 0x000000000C46DB70>
I have already read this article Python: Lambda function in List Comprehensions and I unserstood that you have to use parenthesis to ensure the right execution order.Still i get the same result.