From 7c0d828a2ee318cb2b06b13e1a64c1a401343ec6 Mon Sep 17 00:00:00 2001 From: Ross Ashley Date: Fri, 27 Sep 2013 10:08:09 -0400 Subject: [PATCH] Replaced unnecessary code with one line. --- beetsplug/lastgenre/__init__.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index eba06bc56..b4b7dc783 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -79,25 +79,18 @@ def _is_allowed(genre): return False def _find_allowed(genres): - """Return the first string in the sequence `genres` that is present - in the genre whitelist or None if no genre is suitable. + """Return a string composed of comma delimited genres in the sequence + `genres` that is present in the genre whitelist or an empty string + if no genre is suitable. """ allowed_genres = [] - allowed_genres_copy = [] + for genre in list(genres): if _is_allowed(genre): allowed_genres.append(genre.title()) - for genre in allowed_genres[:-1]: - genre = genre + ', ' - allowed_genres_copy.append(genre) - else: - if allowed_genres: - allowed_genres_copy.append(allowed_genres[-1]) - - genre_str = '' - return genre_str.join(allowed_genres_copy) - + return ','.join(allowed_genres) + def _strings_to_genre(tags): """Given a list of strings, return a genre. Returns the first string that is present in the genre whitelist (or the canonicalization