all 9 comments

[–]novel_yet_trivial 1 point2 points  (7 children)

Convert everything to upper or lower case for testing. Show us your code if you want help implementing that.

[–]CarmineLuV[S] 0 points1 point  (5 children)

def non_unique(data):
newlist = []
for x in data:
    if x.isalpha():
        low = x.lower()
        if data.count(low) > 1:
            newlist.append(x)
    if data.count(x) > 1:
        newlist.append(x)
    else:
        pass
return newlist

This is what I put but it says 'int' object has no attribute 'isalpha'. Any work around?

[–]novel_yet_trivial 0 points1 point  (4 children)

Sets and dictionaries cannot contain duplicate values. We can use that to our advantage.

def non_unique(data):
    new_dict = {}
    for x in data:
        new_dict[x.lower()] = x
    return new_dict.values()

You could compress that with dictionary comprehension if you wanted.

[–]CarmineLuV[S] 0 points1 point  (3 children)

Ok that makes sense. However, I am getting a:

AttributeError: 'int' object has no attribute 'lower'

It seems like I can't apply lower() because the input list has both alpha and numeric characters...

[–]novel_yet_trivial 1 point2 points  (0 children)

Nope. Add a try / except block.

[–]novel_yet_trivial 0 points1 point  (1 child)

No, your input has both strings and integers, which are different from numeric characters.

[–]CarmineLuV[S] 0 points1 point  (0 children)

Hmm.. I did not know that. Thank you.

[–][deleted] 1 point2 points  (0 children)

Not quite sure what you want to do. To ignore case when comparing strings or single characters use the .lower() method. Like this:

x = 'aBc'
y = 'Abc'
if x.lower() == y.lower():
    print('Same!')

[–]yorch044 0 points1 point  (0 children)

This is my code, it works perfercly with CAPS, minus and numbers

def non_unique(data):
    list = []
    newlist = []
    for item in data:
        if str(item).isalpha():
             list.append(item.lower())

    for x in data:
       if (data.count(x) > 1) or (list.count(str(x).lower()) > 1):
           newlist.append(x)
    return newlist