Skip to content

Latest commit

 

History

History
53 lines (30 loc) · 1.16 KB

More_Zeros_than_Ones.md

File metadata and controls

53 lines (30 loc) · 1.16 KB

CodeWars Python Solutions


More Zeros than Ones

Create a moreZeros function which will receive a string for input, and return an array (or null terminated string in C) containing only the characters from that string whose binary representation of its ASCII value consists of more zeros than ones.

You should remove any duplicate characters, keeping the first occurence of any such duplicates, so they are in the same order in the final array as they first appeared in the input string.

'abcde' === ["1100001", "1100010", "1100011", "1100100", "1100101"]
               True       True       False      True       False

        --> ['a','b','d']

'DIGEST'--> ['D','I','E','T']

All input will be valid strings of length > 0. Leading zeros in binary should not be counted.


Given Code

def more_zeros(s):
    return False

Solution

def more_zeros(s):
    chars = [c for c in s if bin(ord(c)).count("0") >= 5]
    uniques = []

    for char in chars:
        if char not in uniques: uniques.append(char)

    return uniques

See on CodeWars.com