Home > Blockchain >  Combining values of two list as one python
Combining values of two list as one python

Time:08-22

arr1=['A', 'B', 'C', 'D', 'E']
arr2=[1, 1, 1, 1, 1]

What I want is to combine both the list as a single value to give Expected output

1A1B1C1D1E

CodePudding user response:

Try:

''.join([str(b) a for a,b in zip(arr1, arr2)])

'1A1B1C1D1E' # Output

It uses list comprehension to combine the string in arr1 to the int converted to string in arr2 and then joins them all together as one string.

CodePudding user response:

arr1=['A', 'B', 'C', 'D', 'E']
arr2=[1, 1, 1, 1, 1]
S = []
for _ in range(len(arr1)):
    S.append(arr1[_])
    S.append(arr2[_])
print(S)
  • Related