1

This are previously defined functions

def make_service(service_data, service_code):
    routes = []

    directions = list(set(map(lambda entry: entry[1], service_data)))  #['1', '2']

    for direction in directions:
        #'1' but if it is '2' then 
        #[('106', '2', '1', '03239'),...('106', '2', '51', '43009')] will be returned for nxt line

        one_direction = filter(lambda entry: entry[1] == direction, service_data)
         #if '1' then [('106', '1', '1', '43009')..('106', '1', '48', '03219')]

        route = map(lambda thing: thing[3], one_direction) #['43009', '43179',..'03218', '03219']

        routes.append(route) #[['43009', '43179',..'03218', '03219']] 

    return lambda t: service_code if t == 0 else (directions if t == 1 else routes)
    # a function is returnrf here ! 


service_106 = make_service(service_106_data, "106")

service_106_data = filter_routes(smrt_routes, "106") 
#[('106', '1', '1', '43009'), ...,('106', '1', '48', '03219'), ('106', '2', '1', '03239'),...('106', '2', '51', '43009')]

So I am suppose to write a function here that returns

[['43009', '43179',..'03218', '43009']]

I have tried:

def get_routes(service):
    return map(lambda x: x, service) # I was thinking that 

service_106_routes = get_routes(service_106)
print(service_106_routes)  # I should get  [['43009', '43179',..'03218', '43009']]

How do I get write a function that extracts [['43009', '43179',..'03218', '43009']] from make_service that actually returns a function lambda t? I don't really know how to start writing my code though... Do I start with t?

1 Answer 1

2

make_service returns a simple lambda function with one argument; t. This lambda function in turn returns either:

  • service_code (t==0);
  • directions (t==1); or
  • routes (any other value of t).

Therefore once you have this function you can access any of these values by providing the appropriate argument, e.g.

106_service_code = service_106(0)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank You !! I got it ! it should be any value that's not 0 or 1 which return the list that I want!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.