Functions to get all latitudes given a list of listing_ids - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Functions to get all latitudes given a list of listing_ids (/thread-19132.html) |
Functions to get all latitudes given a list of listing_ids - Rae - Jun-14-2019 Hi all! Would really appreciate some help here. This is part of my homework (and I am still super new to Python so I need some help). So I have a set of data, and I'm supposed to get all altitudes given a list of listing. Here's my code so far but I have no idea what I'm doing wrong so would appreciate some help! I was given the following hints and I did my code shown after that. Hint Create a results list Extract the latitude and listing id of each row Check listing id exists within the all listings If true, append the latitude into the results list Return results list Input: airbnb_data as data, a list of listing_ids Return: A list of latitudes def get_all_latitude(airbnb_data): results = [] for row in range(airbnb_data): listing_id = row[1] latitude = row[17] if listing_id in airbnb_data: results.append(row) return results RE: Functions to get all latitudes given a list of listing_ids - DeaD_EyE - Jun-14-2019 What is your problem? We have no information about input format, which can differ. If the indices are all right and if there are no rows inside your dataset, which have lesser cols, then it should work. You have to recognize, that indexing begins with 0. If you don't know on which position is what, you could use enumerate. def get_one_row(airbnb_data): first_row = airbnb_data[0] # if airbnb is already a list with rows # if it's text, use the method splitlines on it and then take the first element. for idx, column in enumerate(first_row.split()): print(idx, column)Then you see [(0, "your_column 1"), (1, "your_column 2"), ...] RE: Functions to get all latitudes given a list of listing_ids - Rae - Jun-14-2019 I end up getting this error: Oof I haven't learnt enumerate so I'm going to have to check about that
RE: Functions to get all latitudes given a list of listing_ids - Yoriz - Jun-14-2019 Your function has one parameter, so you can pass it one argument like as follows. def get_all_latitude(parameter1): print(parameter1) get_all_latitude('first argument') but you are trying to pass it two arguments and getting an error like belowdef get_all_latitude(parameter1): print(parameter1) get_all_latitude('first argument', 'second argument') You should either only be passing one argument or add another parameter to your function like belowdef get_all_latitude(parameter1, parameter2): print(parameter1, parameter2) get_all_latitude('first argument', 'second argument')
RE: Functions to get all latitudes given a list of listing_ids - Rae - Jun-14-2019 Thank you!! :) |