0

Say I have list a = [23, 2]. I need to split every element in list and then combine them to one list. So result be like a = [2, 3, 2] What I have for now is:

list = [int(i) for i in str(map([], map(lambda x: x*2, list(reversed(numlist))[1::2])))]

Where map(lambda x: x*2, list(reversed(numlist))[1::2]))) is the list of even indexed numbers (2, 4, 6...) each multiplied by 2.

It gives me: ValueError: invalid literal for int() with base 10: '<' on this line.

1
  • 1
    obviously you are passing an invalid list... please give a minimal reproducible example. Commented Mar 20, 2017 at 0:08

3 Answers 3

3
>>> map(int, ''.join(map(str, a)))
[2, 3, 2]
Sign up to request clarification or add additional context in comments.

Comments

1

You can first change list to string then change this string back to integer list. Here is an example.

a = [23, 2]
a = [int(j) for j in ''.join([str(i) for i in a])]
print(a)

Comments

1

Using two level List Comprehension:

a = [23, 2]
digits = [ int(x) for num in a for x in str(num) ]

1 Comment

list(str(num)) is unnecessary. Just use str(num) you can iterate directly over strings...

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.