Pls someone help me

Joined
Oct 18, 2024
Messages
2
Reaction score
0
I was trying to code a function to delete repetitive characters, but i was using arrays, the trouble is i have 3 repetitive characters like this ['o','o','o'], but my function doesnt save nothing, pls
someone can help me, im really new in this world :c

Screenshot 2024-10-17 215545.png
 
Joined
Dec 10, 2022
Messages
100
Reaction score
26
Please post code instead of images.
Here is something to get you started

Python:
items = ['a','b', 'c', 'c', 'd', 'e', 'c']

def getitems(args):
    alist = []
    for item in args:
        if item not in alist:
            print('Adding item')
            alist.append(item)
        else:
            print('Skipping item. Already in list.')
    return alist

print(getitems(items))

Output

Code:
Adding item
Adding item
Adding item
Skipping item. Already in list.
Adding item
Adding item
Skipping item. Already in list.
['a', 'b', 'c', 'd', 'e']
 
Joined
Jul 4, 2023
Messages
503
Reaction score
63
You can also try using: set
Python:
items = ['f', 'a', 'b', 'c', 'c', 'd', 'e', 'c', 'a', 'c', 'd', 'd']

unique_items = sorted(set(items))
print(unique_items)


BTW, ;)
Python:
def borrarletra(sepa):
    return sorted(set(sepa))


items = ['f', 'a', 'b', 'c', 'c', 'd', 'e', 'c', 'a', 'c', 'd', 'd']
print(borrarletra(items))

items = ['o', 'o', 'o']
print(borrarletra(items))
1729285482073.png
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,039
Messages
2,570,376
Members
47,032
Latest member
OdellBerg4

Latest Threads

Top