-4

For the lists A and B below:

A=[8, 4, 5]

B=[0,0,0,0,0,0,0,0,0,0]

I would like to combine them to give 'C':

C=[8,4,5,0,0,0,0,0,0,0]

Code I have tried:

C = [B(x) for x in A else 0 for x in B]

But I recieve a syntax error.

Can someone help with the correct syntax to achieve the 'Desired Output'. Thankyou.

Georgy
  • 12,464
  • 7
  • 65
  • 73

3 Answers3

1

Do you mean?

C = A + B[len(A):]

Am I missing something here?

kfkhalili
  • 996
  • 1
  • 11
  • 24
1

I am not sure what you mean with combine. If you want to add the lists elementwise I would recommend using numpy:

import numpy as np

a = np.array([1,2,3])
b = np.array([4,5,6])
c = a + b
Jonas
  • 91
  • 2
1

You can also try this.

C = [*A, *B]
Allwin
  • 75
  • 5