Specification: Find directors of movies that Tom Hanks starred in
Example input/output:
Input: actors
movieactor
AMTom Hanks
AMNot Tom Hanks
AMAlso not Tom Hanks
BMOther actor
CMOther actor
Input: directors
directormovie
AAM
ABM
CCM
Output: [A]

Python - Imperative


def tom_hanks(actors,directors):
  r_directors = set()
  for a in actors:
    if 'Tom Hanks' == a['actor']:
      for d in directors:
        if a['movie'] == d['movie']:
          r_directors.add(d['director'])
    return r_directors

Python - Functional


def tom_hanks(actors,directors):
  movies = [a['movie'] for a in actors if a['actor'] == 'Tom Hanks']
  directors = [d['director'] for d in directors if d['movie'] in movies]
  return directors

Python - Pandas


def tom_hanks(actors,directors):
  movies = list(actors.loc[
    actors['actor'] == 'Tom Hanks', 'movie'])
  return directors[directors['movie'].
    isin(movies)]['director']

R - Tidyverse

tom_hanks <- function(actors, directors) {
  actors %>%
    filter(actor == "Tom Hanks") %>%
    inner_join(directors, by = "movie") %>%
    pull(director)
}

SQL - SQLite


SELECT directors.director
FROM 
  directors 
  INNER JOIN actors
  ON directors.movie = 
  actors.movie
WHERE actors.actor="Tom Hanks"

Datalog - Souffle


tom_hanks(Director):-
  actors("Tom Hanks",movie),
  directors(Director,movie).

Q - kdb+

tom_hanks:
  (select director from actors ij (`movie xkey directors) 
   where actor ~\: "Tom Hanks") `director