>>> from phone import ncalls2 >>> v1 = ['934780245', '012', '618776611', '972399700', '11811', ... '972399700', '012', '938765454', '012', '11811', '012', '11811'] >>> with open ('calls.txt', 'w') as f: ... for e in v1: ... a = f.write (e + '\n') >>> ncalls2('calls.txt', 'result.txt') >>> with open('result.txt', 'r') as f: ... a = f.read() >>> a '012 4\n11811 3\n'