Was anyone else confused that this,
# filter list => [ 'ipod', 'ipad', 'iphone' ]
('i' + p) for p in ['mac', 'pod', 'pad', 'phone'] if p.startsWith('p')
applies a filter against the list, rather than limit what gets prefixed with an 'i'?
I'm assuming then there's some code to keep the mapping and the entire list as well. Something like this?
('i' + p) if p.startsWith('p') for p in ['mac', 'pod', 'pad', 'phone']
It just seemed surprising to me that an if statement can cause a change in the list length.
Edit: Ah this seems to be how filtering works in python
Was anyone else confused that this,
# filter list => [ 'ipod', 'ipad', 'iphone' ]
('i' + p) for p in ['mac', 'pod', 'pad', 'phone'] if p.startsWith('p')
applies a filter against the list, rather than limit what gets prefixed with an 'i'?
I'm assuming then there's some code to keep the mapping and the entire list as well. Something like this?
('i' + p) if p.startsWith('p') for p in ['mac', 'pod', 'pad', 'phone']
It just seemed surprising to me that an if statement can cause a change in the list length.
Edit: Ah this seems to be how filtering works in python