[Freeipa-devel] [PATCH 0066] ipactl: Do not start/stop/restart single service multiple times
David Kupka
dkupka at redhat.com
Thu Aug 27 06:07:50 UTC 2015
On 26/08/15 17:49, Tomas Babej wrote:
>
>
> On 08/26/2015 03:16 PM, David Kupka wrote:
>> https://fedorahosted.org/freeipa/ticket/5248
>>
>>
>
> +def deduplicate(lst):
> + new_lst = []
> + s = set(lst)
> + for i in lst:
> + if i in s:
> + s.remove(i)
> + new_lst.append(i)
> +
> + return new_lst
> +
>
> Imho, this method deserves a docstring or at least a comment. It is not
> entrirely clear from the name, that its job is to remove the duplicates
> while preserving the order of the entries.
>
You're right, line or two could not hurt. Patch attached.
> Anyway, deduplication can be implemented in a more readable way:
>
>>>> from collections import OrderedDict
>>>> sample_list = [3,2,1,2,1,5,3]
>>>> OrderedDict.fromkeys(sample_list).keys()
> [3, 2, 1, 5]
I know about this approach and it does not seem much more readable to
me. I just chosen few more lines instead of an import.
>
> Tomas
>
--
David Kupka
-------------- next part --------------
A non-text attachment was scrubbed...
Name: freeipa-dkupka-0067-comment-Add-Documentation-string-to-deduplicate-func.patch
Type: text/x-patch
Size: 844 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20150827/8dc82e66/attachment.bin>
More information about the Freeipa-devel
mailing list