Jump to content

Python - deleting from a list

Go to solution Solved by Enderman,

when you write ['cia','secret','mi6','isi','secret'] it sees that as a single word

try doing

cia secret mi6 isi secret

and then string.split(" ") so that it splits at the spaces

Implement a program that requests a list of words from the user and then prints each word in the list that is not 'secret'.

 

This is how my code looks like

wordInput = input("Enter a list of words: ").split() def not_secret(l:wordInput):    '''Request a list of words from user, then delete any instance of secret'''    for i in l:        if i != 'secret':            print(i)    return not_secret(wordInput)

 

Output should be something like this:

>>> Enter list of words: ['cia','secret','mi6','isi','secret']
cia
mi6
isi
 
What I get is this:
Enter a list of words: ['cia','secret','mi6','isi','secret'] 
['cia','secret','mi6','isi','secret']
 
Can I get some help with this please?
Link to comment
https://linustechtips.com/topic/510891-python-deleting-from-a-list/
Share on other sites

Link to post
Share on other sites

when you write ['cia','secret','mi6','isi','secret'] it sees that as a single word

try doing

cia secret mi6 isi secret

and then string.split(" ") so that it splits at the spaces

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to post
Share on other sites

when you write ['cia','secret','mi6','isi','secret'] it sees that as a single word

try doing

cia secret mi6 isi secret

and then string.split(" ") so that it splits at the spaces

Thank you for answering.

 

You were right. If I input 

cia secret mi6 isi secret

when prompted, I get the correct output. 

Link to post
Share on other sites

Thank you for answering.

 

You were right. If I input 

cia secret mi6 isi secret

when prompted, I get the correct output. 

great :)

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×