Question

In Python, write a function def printAirlineFlightNums(airD): that will print out the names of all of...

In Python, write a function def printAirlineFlightNums(airD): that will print out the names of all of the airlines along with the flight numbers for all flights for that airline.

flightsD={"Delta":{1102:[["IND",1850],["MDW",1955]],
1096:[["PHX",900],["MDW",1255]],
1445:[["ATL",1135],["LAX",1810]],
1776:[["PHL",1350],["RAP",1610]],
1226:[["PHX",950],["MDW",1345]],
1885:[["ATL",1305],["LAX",2000]],
1009:[["MDW",1850],["IND",1955]],
9001:[["MDW",2145],["IND",2255]]},
"Southwestern":{1111:[["SAT",430],["MDW",825]],
2121:[["MDW",430],["SAT",825]],
4335:[["PHX",450],["MDW",745]],
1102:[["MDW",1100],["PHX",1450]]},
"American":{7765:[["IND",1850],["CHA",2105]],
2133:[["BNA",900],["IND",1115]],
3321:[["HOU",1335],["ATL",1615]],
2100:[["BNA",900],["IND",1115]],
4311:[["HOU",905],["ATL",1255]],
5577:[["ATL",1100],["HOU",1350]],
1102:[["BNA",1100],["HOU",1450]]}}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def printAirlineFlightNums(flightsD, airD):
    result = []
    for x in flightsD.keys():
        if airD in flightsD[x].keys():
            result.append(x)
    print("The names of airlines with flight",airD,":",result)

if __name__ == '__main__':
    flightsD = {"Delta": {1102: [["IND", 1850], ["MDW", 1955]],
                          1096: [["PHX", 900], ["MDW", 1255]],
                          1445: [["ATL", 1135], ["LAX", 1810]],
                          1776: [["PHL", 1350], ["RAP", 1610]],
                          1226: [["PHX", 950], ["MDW", 1345]],
                          1885: [["ATL", 1305], ["LAX", 2000]],
                          1009: [["MDW", 1850], ["IND", 1955]],
                          9001: [["MDW", 2145], ["IND", 2255]]},
                "Southwestern": {1111: [["SAT", 430], ["MDW", 825]],
                                 2121: [["MDW", 430], ["SAT", 825]],
                                 4335: [["PHX", 450], ["MDW", 745]],
                                 1102: [["MDW", 1100], ["PHX", 1450]]},
                "American": {7765: [["IND", 1850], ["CHA", 2105]],
                             2133: [["BNA", 900], ["IND", 1115]],
                             3321: [["HOU", 1335], ["ATL", 1615]],
                             2100: [["BNA", 900], ["IND", 1115]],
                             4311: [["HOU", 905], ["ATL", 1255]],
                             5577: [["ATL", 1100], ["HOU", 1350]],
                             1102: [["BNA", 1100], ["HOU", 1450]]}}

    printAirlineFlightNums(flightsD, 1102)
    printAirlineFlightNums(flightsD, 2100)

Add a comment
Know the answer?
Add Answer to:
In Python, write a function def printAirlineFlightNums(airD): that will print out the names of all of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT