Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
filtering python3
list_of_stuff = [ "aus-airport-1", "aus-airport-2", "us-airport-1", "us-airport-2", "aus-ship-1", "us-ship-99", "nz-airport-1"] is_airport = lambda x: "-airport-" in x is_ship = lambda x: "-ship-" in x airports_excluding_nz = lambda x: is_airport(x) and not x.startswith("nz-") airports_in_aus = lambda x: is_airport(x) and x.startswith("nz-") ships = lambda x: is_ship(x) print ("all regions excluding nz:" , ", ".join( filter(lambda x: airports_excluding_nz(x) , list_of_stuff) ) ) print ("all regions in aus:", ", ".join( filter(lambda x: airports_in_aus(x) , list_of_stuff) ) ) print ("all ships:", ", ".join( filter(lambda x: ships(x) , list_of_stuff) ) )
run
|
edit
|
history
|
help
0
linked_lists_2+decisions
Lesson 4 HW
Sk
Basic_if_else.py
abracadabra
Guessing game
PyMeta
Python
dictionary function
Multinomial Naive Bayes