wiki:python/Types/list

count, sort

See also:

Linked list
List comprehension
collections/deque


Python Doc: Mutable Sequence Types
Python Tutorial


Flache Liste aus 2D-Liste erstellen

Making a flat list out of list of lists in Python

>>> nested = [[1, 2, 3], [4], [5, 6]]
>>> [item for sublist in nested for item in sublist]
[1, 2, 3, 4, 5, 6]
>>> sum(nested, [])
[1, 2, 3, 4, 5, 6]
>>> reduce(lambda x,y: x+y,l)
[1, 2, 3, 4, 5, 6]
>>> list(itertools.chain.from_iterable(nested))
[1, 2, 3, 4, 5, 6]

Duplikate aus Listen entfernen

Re: Doppelte Elemente aus zwei Listen entfernen

>>> first = ['A','B','C','D']
>>> second = ['B','C','E']
>>> set(second) - set(first)
set(['E'])
>>> first = ['A','B','C','D']
>>> second = ['B','C','E']
>>> [e for e in second if e not in first]
['E']

Effektiver Umgang mit großen Listen
Sequenz als list index verwenden...
Listenelemente mit 'Trennzeichen' trennen...

Last modified 6 years ago Last modified on Oct 15, 2013, 4:24:39 PM