3

I have 2 lists:

c = [91.0, 92.0, 93.0, 94.0]
a = ['1,2,3,4', '1,2', '4,5,6', '']

result = [911, 912, 913, 914, 921, 922, 934, 935, 936, 94]

I tried this but still unable to get what I exactly want

result = [x for x in zip(c,a)]

Please help me.

2
  • 5
    please explain it more precicely how do u want it.. Commented Apr 16, 2014 at 11:49
  • You are not zipping or merging; you apparently are creating a modified product. Commented Apr 16, 2014 at 11:51

2 Answers 2

4

You can do it as follows:

c = [91.0, 92.0, 93.0, 94.0]
a = ['1,2,3,4', '1,2', '4,5,6', '']

c = map(str, map(int, c))

x = [int(c[k]+j) for k,i in enumerate(a) for j in i.split(',')]

>>> print x
[911, 912, 913, 914, 921, 922, 934, 935, 936, 94]
Sign up to request clarification or add additional context in comments.

Comments

1

I tried to keep it readable:

C = [91.0, 92.0, 93.0, 94.0]
A = ['1,2,3,4', '1,2', '4,5,6', '']

result = []
for c, a in zip(C,A):
  str_c = str(int(c))
  nums = a.split(',')
  for num in nums:
    result.append(int(str_c + num))


print(result)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.