Moving items from list to list
George Sakkis
george.sakkis at gmail.com
Thu Jun 14 16:18:51 EDT 2007
On Jun 14, 12:30 pm, HMS Surprise <j... at datavoiceint.com> wrote:
> Just wondered if there was some python idiom for moving a few items
> from one list to another. I often need to delete 2 or 3 items from one
> list and put them in another. Delete doesn't seem to have a return
> value. I don't care which items I get so now I just use a couple of
> pops or a for loop for more than two.
>
> Thanks
>
> jh
>>> x = range(10)
>>> y = []
>>> y.append(x.pop(4))
>>> print x, y
[0, 1, 2, 3, 5, 6, 7, 8, 9] [4]
>>> y.append(x.pop(7))
>>> print x, y
[0, 1, 2, 3, 5, 6, 7, 9] [4, 8]
HTH,
George
More information about the Python-list
mailing list