Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to extend a list with iterable and non-iterable object in one line?

Lets say I have 3 objects:

object1 = [1, 2, 3]
object2 = 'string'
object3 = {'key': 10}

I am trying to create a new list object in one line such that it looks like this:

object4 = [1, 2, 3, 'string', {'key': 10}]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you can use unpacking for the iterables:

object4 = [*object1,object2,object3]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading