I’m trying to merge two lists if they contain a certain word.
My code works fine until I try to transfer it to under a function or under a for loop.
When I do I get:
TypeError: argument 2 to map() must support iteration
I also tried replacing map(None, a,b) with itertools.imap(None, a,b) as suggested in other posts but get :
TypeError: 'int' object is not iterable
Any suggestions?
a = 0
b = 0
row_combine = []
for row in blank3:
if 'GOVERNMENTAL' in row:
a = row
if 'ACTIVITIES' in row:
b = row
c = map(None, a,b) #problem is here
for row in c:
row1 = []
if row[0] == None:
row1.append(''.join([''] + [row[1]]))
else:
row1.append(''.join([row[0]] + [' '] + [row[1]]))
row_combine.append(''.join(row1))
output for a:
a = [' ', u'GOVERNMENTAL', u'BUSINESS-TYPE']
output for b:
b = [u'ASSETS', u'ACTIVITIES', u'ACTIVITIES', u'2009', u'2008', u'JEDO']
need it to be:
[ u'ASSETS', u'GOVERNMENTAL ACTIVITIES', u'BUSINESS-TYPE ACTIVITIES', u'2009', u'2008', u'JEDO']
hence the for for loop after map function.
If after iterating through
blank3you never encounter both ‘GOVERNMENTAL’ and ‘ACTIVITIES’,aorbcould be 0, which will cause map to fail. You could startaandboff as empty lists, or check your input before themap()Meanwhile, instead of the for loop:
Which yields: