def removeCity(cityName): #Check if the city is in the city dictionary if cityName in QueryingData.cityDicationary: cityCode = UserQuerying.nameToCode(cityName) continentInfo = QueryingData.cityDicationary[cityName].continent #Remove from the cityDicationary del QueryingData.cityDicationary[cityName] #Remove the city from the take off port for route in QueryingData.routeList: if route.takeoffPortCode == cityCode: UserQuerying.minusHubCity(cityCode) QueryingData.routeList.remove(route) #Remove the city from the land port for route in QueryingData.routeList: if route.landPortCode == cityCode: UserQuerying.minusHubCity(route.takeoffPortCode) QueryingData.routeList.remove(route) else: print 'Cannot find ' + cityName
def removeRoute(): ''' This function will remove a particular route, And update all the relevant data ''' sourcePortName = raw_input("Please enter the source port you want to remove: \n") destPortName = raw_input("Please enter the destination port you want to remove: \n") sourcePortCode = UserQuerying.nameToCode(sourcePortName) destPortCode = UserQuerying.nameToCode(destPortName) for route in QueryingData.routeList: #Remove source to destination if route.takeOffPortCode == sourcePortCode and route.landPortCode == destPortCode: QueryingData.routeList.remove(route) UserQuerying.minusHubCity(sourcePortCode) break for route in QueryingData.routeList: #Remove destination to source if route.takeOffPortCode == destPortCode and route.landPortCode == sourcePortCode: QueryingData.routeList.remove(route) UserQuerying.minusHubCity(destPortCode) break
def removeCity(): ''' This function will remove a city from existing cities, and update all the relevant data ''' cityName = raw_input("Please enter the city you want to remove: \n") if cityName in QueryingData.cityDicationary: #Check if the input city is valid or not cityCode = UserQuerying.nameToCode(cityName) del QueryingData.continent[cityName] #Remove the city from the continent del QueryingData.cityDicationary[cityName] #Remove from the cityDicationary #Remove relevant routes including the remove city deleteRoute = [route for route in QueryingData.routeList if route.takeOffPortCode == cityCode] QueryingData.routeList[:] = [route for route in QueryingData.routeList if route.landPortCode != cityCode and route.takeOffPortCode != cityCode] for route in deleteRoute: UserQuerying.minusHubCity(route.takeOffPortCode) UserQuerying.minusHubCity(route.landPortCode) else: print 'Cannot find ' + cityName #Invalid input