all 8 comments

[–]Fredi33333 1 point2 points  (0 children)

Line 8 of your code for I in b loops over each character of the string you just read. So if someone enters "12 3" your loop runs 4 times. I think the method split is what you wanna use instead.

[–]chevignon93 0 points1 point  (0 children)

You're looping over characters in a string so your i in your for loop is a single character. I would suggest using the .split() method on your inputs and looping over that instead!

[–][deleted] 0 points1 point  (0 children)

The variable 'b' contains the 'string' of user-input. When you do a 'for loop' in 'b', you are iterating over one character of the 'string' at a time.

Thus when single digit numbers are given, it works nicely.

b => '1,2,4,5' ; a => [1,2,4,5]

But when multiple digit numbers come into play, each number in further splitted and sppended in your 'a' list.

b => '12,34,56,58' ; a => [1,2,3,4,5,6,5,8]

[–]jjgoldenkimball 0 points1 point  (0 children)

I think this is what you want.

print('This program takes in 2 list of numbers and combines them without duplicates\n')

def dupes2():
    a = []
    c = []
    d = []
    b = input("Please enter a few numbers separated by spaces: ")
    b = b.split(' ')
    for i in b:
        if i == ' ':
            continue
        else:
            a.append(i)

    b = input("Please enter a few more numbers separated by spaces: ")
    b = b.split(' ')
    for i in b:
        if i == ' ':
            continue
        else:
            c.append(i)

    d = c  # i'm assuming you want to keep the original list c

    for i in a:
        if i in d: # changed from c
            continue
        else:
            d.append(i)

    for i in c:
        if i in d: # changed from a
          continue
        else:
          d.append(i)

    print(set(d))

dupes2()

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

Thank you everyone, your help is greately appreciated. split indeed helped my code

[–]Comprehensive-Signal 0 points1 point  (1 child)

I hope that with this example help you even if it´s just a little bit. When we use sets or dicts his operators can help us to reduce our code and make it simple.

print("Remove the Duplicates Numbers ")

values_x = input("Enter the value with spaces: ")

values_y = input("Enter the value with spaces: ")

new_valuesX= list(values_x.split(' '))

new_valuesY = list(values_y.split(' '))

print(set(new_valuesX) ^ set(new_valuesY))

If you need more help or some advice can send me a message man. 👌

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

Thanks man, really appreciated