#๐Ÿ”’ How to delete a list in another list by using one of it itens

22 messages ยท Page 1 of 1 (latest)

atomic birch
#

Hello! I'm new to python (and programming in general) and i need some help in a software I'm currently working with (it's a school project). Basically, I need to receive the ID number and analyse to see if it is in a list I've created previously. However, I'm having problems to do it. I have two lists, one with other list inside (FUNC) and one with some information (Name, ID and Work) (DADOS). Then, I have to receive an ID and see if it is in the sub-list. If it is, i need to remove the sub-list from the big list. However, I cannot do that. When i put the ID (which is in the sublist DADOS), the program say it didnt find the ID there. I'm using the following: py id= input('Put the ID here:').replace('.','').replace('- ','').replace(',','').replace(' ','') if id in func: func.remove('dados') else: print('\033[31mID not found\033[m') id = input('Write the ID again:').replace('.','').replace('-','').replace(',','').replace(' ','')

spark skyBOT
#

@atomic birch

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

civic canyon
#

i'm not so sure it's easier to show - i don't speak your language

i do see a likely problem though:

cpf = input(...)
if 'cpf' in func:
    ...```
the cpf variable is not used, you create a string made of the characters 'c', 'p', and 'f'
atomic birch
weary silo
#

EDIT: Inuk had the command to write it

atomic birch
weary silo
#

no worries, just makes things look nicer

civic canyon
#

!code

spark skyBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

atomic birch
idle tide
#

you need the ```py for the first line, just ``` won't give you syntax highlighting

idle tide
#

has to be a separate line

#

```py
foo
bar
baz
```

atomic birch
idle tide
#

what do you expect to happen and what happens in practice when you run your code

atomic birch
#

when i put an ID that does exist in the list "dados", i expect it [dados] to be removed from a bigger list, "func". however, when i put the ID that does exist, for some reason the program acts as if it didnt (it executes the else, not the if), asking me for another ID

idle tide
#

are you sure the id is in func?

#

where is func defined? in the code snippet you've shared, you never push to func

atomic birch
#

yeah, i know cuz when i ask print(func), the ID is printed

spark skyBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.