So I have a code to give a position of a character in a text file, using my function code that looks like this
#this is defined function
def return_position(arr, search_for=[''], base=1):
dim = ()
arr = [str(arr) for arr in arr]
for search in search_for:
for sr in range(len(arr)):
s = arr[sr]
for cr in range(len(s)):
c = s[cr]
if c == search:
dim += [(cr+base, sr+base)]
return dim
In order to get the list of file, I used .readlines()
because it's containing a list and will get the expected result, so I did
#open the file and read it as a list
textlist = open('testfile.text', 'r').readlines()
#textlist = ['Build a machine\n', 'For the next generation']
#print the return_position as a lines
print(''.join(return_position(textlist, search_for=['a', 'b'])))
In testfile.txt
Build a machine
For the next generation
Expected result
(1, 1)
(7, 1)
(10, 1)
(19, 2)
But why it's returning
TypeError can only concatenate tuple (not "list") to tuple