From c7acc67659990de246d2ac9d9f9961fd3a047e4b Mon Sep 17 00:00:00 2001 From: Gaddeti Rohit Babu <30732419+rohitbabugaddeti@users.noreply.github.com> Date: Thu, 18 Feb 2021 17:52:25 +0530 Subject: [PATCH] update hamming_distance.md `list()` is not required since `str` itself has `count()` --- snippets/hamming_distance.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/hamming_distance.md b/snippets/hamming_distance.md index 9740736fa..2e46b3d24 100644 --- a/snippets/hamming_distance.md +++ b/snippets/hamming_distance.md @@ -7,11 +7,11 @@ Calculates the Hamming distance between two values. - Use the XOR operator (`^`) to find the bit difference between the two numbers. - Use `bin()` to convert the result to a binary string. -- Convert the string to a list and use `list.count()` to count and return the number of `1`s in it. +- Convert the string to a list and use `count()` of `str` class to count and return the number of `1`s in it. ```py def hamming_distance(a, b): - return list(bin(a ^ b)).count('1') + return bin(a ^ b).count('1') ``` ```py