-4

The function merges two lists of the same length, the first of strings, the second of integers.

The function is:

def switchlist(n,m):
f=[]
z = range(0,len(m))
for k in z:
    f.append(n[k])
    f.append(m[k])
return f

The list is correct, except that it returns: ['yes', 2, 'always', 4], instead of: [('yes', 2), ('always', 4)] (if those are the two strings and the two integers)

Does anybody know how to fix the brackets?

VLC
  • 127
  • 7

1 Answers1

1

A zip would work. First, it needs to be a list. So f = list(zip(n, m)) Or at the first, you could make f = [(), ()] and append it. Zipping is easier.

jinwon2
  • 84
  • 11