Home › Coding › Below is an instruction that describes a task. Write a respo...
Below is an instruction that describes a task. Write a respo...
Coding · Gemini, GPT-5.6, Claude · Coding
56Quality
88%Useful
85Reliability
The prompt
Below is an instruction that describes a task. Write a response that appropriately completes the request. ### Instruction: Create a Python function that takes a list containing fruit names and returns the most common fruit name. ### Input: ['Apple', 'Orange', 'Apple', 'Pineapple', 'Grape', 'Apple'] ### Output: def most_common_fruit(fruit_list): # Dictionary to get count of each fruit freq_dict = {} # Count frequency of each fruit for fruit in fruit_list: if fruit in freq_dict: freq_dict[fruit] += 1 else: freq_dict[fruit] = 1 # Get maximum frequency max_freq = 0 for freq in freq_dict.values(): if freq > max_freq: max_freq = freq # Get the most common fruit most_common_fruit = None for fruit, freq in freq_dict.items(): if freq == max_freq: most_common_fruit = fruit break return most_common_fruit