I'm trying to filter an item from a list, and I'm getting a syntax error: SyntaxError: invalid syntax
The code:
a['name'] = 'Dan'
b['name'] = 'Joe'
ppl = [a,b]
inputName = raw_input('Enter name:').strip()
person = [p in ppl if p['name']==inputName].pop()
any idea?
[item for item in array]
not
[item in array]
First of all, you should use dictionary instead of list if you want to use 'name' key. It should look like this
a = {'name':'Dan'}
b = {'name':'Joe'}
ppl = [a,b]
for p in ppl:
if(p['name']==inputName):
person=ppl.pop(ppl.index(p))
Maybe there is a better way, more pythonic, but this one working ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With