I don't have much experience with Python. I'm trying to code in a functional style like I'm used to from Java and JavaScript e.g.
var result = getHeroes('Jedi')
.map(hero => { hero: hero, movies: getMovies(hero) })
.filter(x => x.movies.contains('A New Hope'));
I'm trying to do something similar in Python but I can't get the same chaining style. I had to break it down to two statements, which I don't like:
tmp = ((hero, get_movies(hero)) for hero in get_heroes('jedi'))
result = ((hero, movies) for (hero, movies) in tmp if movies.contains('A New Hope')
I have two questions:
- Is there a way in Python to approach the first style?
- What is the idiomatic way of doing this in Python?
Thank you.