[libvirt] [PATCH 12/22] apibuild: Simplify uniq function

Radostin Stoyanov posted 22 patches 7 years, 3 months ago
[libvirt] [PATCH 12/22] apibuild: Simplify uniq function
Posted by Radostin Stoyanov 7 years, 3 months ago
Use a set (unordered collections of unique elements) [1] to remove
repeated elements in a list.

1: https://docs.python.org/3/tutorial/datastructures.html#sets

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
---
 docs/apibuild.py | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/docs/apibuild.py b/docs/apibuild.py
index 8fecf5a81..149cd41cc 100755
--- a/docs/apibuild.py
+++ b/docs/apibuild.py
@@ -130,11 +130,7 @@ def escape(raw):
     return raw
 
 def uniq(items):
-    d = {}
-    for item in items:
-        d[item] = 1
-    k = sorted(d.keys())
-    return k
+    return sorted(set(items))
 
 class identifier:
     def __init__(self, name, header=None, module=None, type=None, lineno=0,
-- 
2.14.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 12/22] apibuild: Simplify uniq function
Posted by Daniel P. Berrangé 7 years, 3 months ago
On Sat, Mar 17, 2018 at 02:23:30PM +0000, Radostin Stoyanov wrote:
> Use a set (unordered collections of unique elements) [1] to remove
> repeated elements in a list.
> 
> 1: https://docs.python.org/3/tutorial/datastructures.html#sets
> 
> Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
> ---
>  docs/apibuild.py | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list