Ask Your Question
1

unpacking list in a list

asked 2018-01-11 22:16:35 +0100

anonymous user

Anonymous

Hi, I'm trying to convert a sympy code to sage.

I have found that the following does not work:

sector1 = [1,2,3]
sector2 = [4,5,6]
newlist = [*sector1, sector2]

even though the unpacking works for functions (ex F(*sector1)).

How do I do that?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2018-01-22 16:16:27 +0100

Iguananaut gravatar image

For what it's worth, more "generalized" star unpacking is supported in more recent versions of Python 3 (I think 3.5+, maybe 3.6+):

>>> a = [1, 2, 3]
>>> b = [4, 5, 6]
>>> [*a, b]
[1, 2, 3, [4, 5, 6]]

This is just a general Python question though. Sage doesn't use Python 3 by default yet, though the next version will have significant progress toward Python 3 support.

edit flag offensive delete link more
1

answered 2018-01-11 22:21:43 +0100

vdelecroix gravatar image

You should learn about Python lists

sage: sector1 + sector2
[1, 2, 3, 4, 5, 6]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-01-11 22:16:35 +0100

Seen: 403 times

Last updated: Jan 22 '18