Different functions return the same item from a Python dictionary
<pre><code>import json, os

def load_data(filepath):
    if not os.path.exists(filepath):
        return None
    with open(filepath, 'r') as file:
        return json.load(file)

def get_biggest_bar(data):
    bars = []
    for bar in data:
        bars.append((bar['Cells']['SeatsCount'] , bar['Number']))
    max_number = max(bars)[1]
    (item for item in data if item['Number'] == max_number).__next__()    
    return item, max_number

def get_smallest_bar(data):
    bars = []
    for bar in data:
        bars.append((bar['Cells']['SeatsCount'] , bar['Number']))
    min_number = min(bars)[1]
    (item for item in data if item['Number'] == min_number).__next__()    
    return item, min_number

def get_closest_bar(data, longitude, latitude):
    coordinates = []
    def get_distance(point, input_point):
        return ((longitude-input_point[0])**2 + (latitude - input_point[1])**2)**1/2
    for cell in data:
        coordinates.append([cell['Cells']['geoData']['coordinates'],cell['Number']])
    for coor in coordinates:
        coor[0] = get_distance(point, coor[0])
    closest_bar = min(coordinates)[1]
    (item for item in data if item['Number'] == closest_bar).__next__()
    return item, closest_bar

if __name__ == '__main__':
    data = load_data("Bars.json")
    print(get_smallest_bar(data))
    print(get_biggest_bar(data))
    print(get_closest_bar(data, 50.0, 50.0))
</code></pre>

<p>And it's output is:</p>

<pre><code>(dict_values(['Ð¡ÐµÐ¼ÑÐ½Ð¾Ð²ÑÐºÐ¸Ð¹ Ð¿ÐµÑÐµÑÐ»Ð¾Ðº, Ð´Ð¾Ð¼ 21', 'Ð½ÐµÑ', 'ÑÐ°Ð¹Ð¾Ð½ Ð¡Ð¾ÐºÐ¾Ð»Ð¸Ð½Ð°Ñ ÐÐ¾ÑÐ°', 'ÐÐ¾ÑÑÐ¾ÑÐ½ÑÐ¹ Ð°Ð´Ð¼Ð¸Ð½Ð¸ÑÑÑÐ°ÑÐ¸Ð²Ð½ÑÐ¹ Ð¾ÐºÑÑÐ³', 'Ð´Ð°', 177, {'type': 'Point', 'coordinates': [37.717115000077776, 55.78262800012168]}, 'Ð¡ÐÐ', 272459722, [{'PublicPhone': '(916) 223-32-98'}], 'SÐÐ']), 37)
(dict_values(['Ð¡ÐµÐ¼ÑÐ½Ð¾Ð²ÑÐºÐ¸Ð¹ Ð¿ÐµÑÐµÑÐ»Ð¾Ðº, Ð´Ð¾Ð¼ 21', 'Ð½ÐµÑ', 'ÑÐ°Ð¹Ð¾Ð½ Ð¡Ð¾ÐºÐ¾Ð»Ð¸Ð½Ð°Ñ ÐÐ¾ÑÐ°', 'ÐÐ¾ÑÑÐ¾ÑÐ½ÑÐ¹ Ð°Ð´Ð¼Ð¸Ð½Ð¸ÑÑÑÐ°ÑÐ¸Ð²Ð½ÑÐ¹ Ð¾ÐºÑÑÐ³', 'Ð´Ð°', 177, {'type': 'Point', 'coordinates': [37.717115000077776, 55.78262800012168]}, 'Ð¡ÐÐ', 272459722, [{'PublicPhone': '(916) 223-32-98'}], 'SÐÐ']), 434)
(dict_values(['Ð¡ÐµÐ¼ÑÐ½Ð¾Ð²ÑÐºÐ¸Ð¹ Ð¿ÐµÑÐµÑÐ»Ð¾Ðº, Ð´Ð¾Ð¼ 21', 'Ð½ÐµÑ', 'ÑÐ°Ð¹Ð¾Ð½ Ð¡Ð¾ÐºÐ¾Ð»Ð¸Ð½Ð°Ñ ÐÐ¾ÑÐ°', 'ÐÐ¾ÑÑÐ¾ÑÐ½ÑÐ¹ Ð°Ð´Ð¼Ð¸Ð½Ð¸ÑÑÑÐ°ÑÐ¸Ð²Ð½ÑÐ¹ Ð¾ÐºÑÑÐ³', 'Ð´Ð°', 177, {'type': 'Point', 'coordinates': [37.717115000077776, 55.78262800012168]}, 'Ð¡ÐÐ', 272459722, [{'PublicPhone': '(916) 223-32-98'}], 'SÐÐ']), 170)
</code></pre>

<p>As you see, items are COMPLETLY identical, but they are diffrent(I tried to devide functions and run them seperatly, and they output diffrent items)! Also, you can see the second number in the fucntion's returns - they are diffrent! Whats the matter?!</p>

<p>Answers what went wrong have been given. Im my opinion the code searching for min and max was not "pythonic". I'd like to suggest another approach:</p>

<p>(Using sample data from Kenny Ostrom's answer)</p>

<pre><code>data = [ {'Number': 10, 'Cells': {'SeatsCount': 10, 'geoData': {'coordinates': (10, 10)}}},
         {'Number': 50, 'Cells': {'SeatsCount': 50, 'geoData': {'coordinates': (50, 50)}}},
         {'Number': 90, 'Cells': {'SeatsCount': 90, 'geoData': {'coordinates': (90, 90)}}} ]

biggest = max(data, key=lambda bar: bar['Cells']['SeatsCount'])
smallest = min(data, key=lambda bar: bar['Cells']['SeatsCount'])
</code></pre>

<p>for the closest bar a simple custom key function based on the <code>get_distance</code> from the original code is required, but you got the idea.</p>

python dictionary