# join lists?

Hello! Is there a way to join two lists? For example, v=[1,2,3]; w=[4,5,6];

how can I obtain the list z=[1,2,3,4,5,6]? Thank you very much, Francesco

join lists?

asked
**
2012-02-03 10:21:13 -0500
**

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hello! Is there a way to join two lists? For example, v=[1,2,3]; w=[4,5,6];

how can I obtain the list z=[1,2,3,4,5,6]? Thank you very much, Francesco

add a comment

1

answered
**
2012-02-03 10:31:26 -0500
**

This post is a wiki. Anyone with karma >750 is welcome to improve it.

You can simply add them:

```
sage: a = [1,2,3]
sage: b = [4,5,6]
sage: z = a+b
sage: z
[1, 2, 3, 4, 5, 6]
```

Note that you can't subtract them, though:

```
sage: a-b
Traceback (most recent call last):
...
TypeError: unsupported operand type(s) for -: 'list' and 'list'
```

This is basically because it's not obvious what to do with [1,2,3]-[4,5], and a fundamental Python principle is to resist the temptation to guess in the face of ambiguity.

It might be helpful to work through a Python tutorial.

2

In other words, lists form a semigroup. If you want subtraction you have to go through the Grothendiek construction....

Asked: **
2012-02-03 10:21:13 -0500
**

Seen: **2,525 times**

Last updated: **Feb 03 '12**

Print symbolic variables like a_1 in A[1] style

How to plot the output of A.eigenvectors_right()?

How do I define a list of products of matrices from a given list?

Evaluating a list of multivariate equations at random values.

How to obtain all finite connected distributive lattices with SAGE

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.