[kupfer] plugin.rhythmbox: Use itertools.groupby



commit 461a58ccdb2033e589cbd0bb9d687751cdff7243
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Thu Aug 20 19:59:40 2009 +0200

    plugin.rhythmbox: Use itertools.groupby

 kupfer/plugin/rhythmbox.py |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/kupfer/plugin/rhythmbox.py b/kupfer/plugin/rhythmbox.py
index 0df694c..603b410 100644
--- a/kupfer/plugin/rhythmbox.py
+++ b/kupfer/plugin/rhythmbox.py
@@ -1,6 +1,8 @@
-import gio
+import itertools
 from hashlib import md5
 
+import gio
+
 from kupfer.objects import (Leaf, Source, AppLeaf, Action, RunnableLeaf,
 		SourceLeaf, AppLeafContentMixin)
 from kupfer import objects, icons, utils, config
@@ -308,19 +310,18 @@ class RhythmboxArtistsSource (Source):
 		yield ArtistLeaf
 
 def _locale_sort_artist_album_songs(artists):
-	"""Sort dictionary @artists by Artist, then Album,
+	"""Locale sort dictionary @artists by Artist, then Album;
 	each artist in @artists should already contain songs
 	grouped by album and sorted by track number.
 	"""
 	for artist in utils.locale_sort(artists):
 		artist_songs = artists[artist]
-		albums = set(s["album"] for s in artist_songs)
+		albums = {}
+		albumkey = lambda song: song["album"]
+		for album, songs in itertools.groupby(artist_songs, albumkey):
+			albums[album] = list(songs)
 		for album in utils.locale_sort(albums):
-			album_songs = []
-			for song in artist_songs:
-				if song["album"] == album:
-					album_songs.append(song)
-			for song in album_songs:
+			for song in albums[album]:
 				yield song
 
 class RhythmboxSongsSource (Source):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]