日付と名前のペアごとに1つのサブリストを取得したいようです。これは辞書の良い使用例のようです。(date、name)がキーであり、そのペアの最も古いレコードが値です。
#uses an iterable `seq` to populate a dictionary.
#the function `keyFunc` will be called on each element of seq to generate keys.
#if two elements `a` and `b` have the same key,
#`compFunc(a,b)` will return which element should belong in the dict.
def make_dict(seq, keyFunc, compFunc):
d = {}
for element in seq:
key = keyFunc(element)
if key not in d:
d[key] = element
else:
d[key] = compFunc(d[key], element)
return d
#I've put all your elements in quotes so that it's valid python.
#You can use whatever types you prefer,
#as long as the date and name can be used as a key,
#and the time supports comparison.
NestedList = [
['100', '08/08/2012', '08:00', 'John Smith'],
['100', '08/09/2012', '09:20', 'John Smith'],
['100', '08/08/2012', '10:00', 'John Smith'],
['131', '08/10/2012', '08:00', 'Jane Williams'],
['131', '08/12/2012', '22:00', 'Jane Williams']
]
#the key is generated from the element's date and name
keyFunc = lambda x: (x[1], x[3])
#prefer the element with the smaller time
compFunc = lambda a,b: a if a[2] < b[2] else b
NewList = make_dict(NestedList, keyFunc, compFunc).values()
NewList.sort() #optional
print NewList
出力:
[
['100', '08/08/2012', '08:00', 'John Smith'],
['100', '08/09/2012', '09:20', 'John Smith'],
['131', '08/10/2012', '08:00', 'Jane Williams'],
['131', '08/12/2012', '22:00', 'Jane Williams']
]