Easy methods to Discover the Distinctive String in Python

0
8
Adv1


Adv2

The problem

There may be an array of strings. All strings comprise related letters besides one. Attempt to discover it!

find_uniq([ 'Aa', 'aaa', 'aaaaa', 'BbBb', 'Aaaa', 'AaAaAa', 'a' ]) # => 'BbBb'
find_uniq([ 'abc', 'acb', 'bac', 'foo', 'bca', 'cab', 'cba' ]) # => 'foo'

Strings might comprise areas. Areas should not important, solely non-spaces symbols matter.
E.g. A string that accommodates solely areas is like an empty string.

It’s assured that the array accommodates greater than 3 strings.

The answer in Python code

Possibility 1:

def find_uniq(arr):
    arr.type(key=lambda x: x.decrease())
    arr1 = [set(i.lower()) for i in arr]
    return arr[0] if arr1.rely(arr1[0]) == 1 and str(arr1[0]) != 'set()' else arr[-1]

Possibility 2:

def find_uniq(arr):
    for phrase in set(arr):
        for letter in set(phrase):
            if sum([1 if letter in w else 0 for w in arr]) == 1:
                return phrase
            else: proceed

Possibility 3:

from collections import Counter
def find_uniq(arr):
    res = Counter(''.be a part of(arr)).most_common()
    return ''.be a part of([x for x in arr if res[-1][0] in x])

Take a look at instances to validate our resolution

check.describe('ought to deal with pattern instances')
check.assert_equals(find_uniq([ 'Aa', 'aaa', 'aaaaa', 'BbBb', 'Aaaa', 'AaAaAa', 'a' ]), 'BbBb')
check.assert_equals(find_uniq([ 'abc', 'acb', 'bac', 'foo', 'bca', 'cab', 'cba' ]), 'foo')
check.assert_equals(find_uniq([ '    ', 'a', '  ' ]), 'a')
Adv3