bcb-0002
1.000
Proposed solution
```python
import random
import statistics
def task_func(LETTERS):
"""
Create a dictionary in which keys are random letters and values are lists of random integers.
The dictionary is then sorted by the mean of the values in descending order, demonstrating the use of the statistics library.
Parameters:
LETTERS (list of str): A list of characters used as keys for the dictionary.
Returns:
dict: The sorted dictionary with letters as keys and lists of integers as values, sorted by their mean values.
Requirements:
- random
- statistics
Example:
>>> import random
>>> random.seed(42)
>>> sorted_dict = task_func(['a', 'b', 'c'])
>>> list(sorted_dict.keys())
['a', 'b', 'c']
>>> isinstance(sorted_dict['a'], list)
True
>>> type(sorted_dict['a']) # Check type of values
<class 'list'>
"""
# Create dictionary with random letters as keys and lists of random integers as values
result_dict = {}
for letter in LETTERS:
# Generate a random list of integers (length between 1 and 10)
list_length = random.randint(1, 10)
random_list = [random.randint(1, 100) for _ in range(list_length)]
result_dict[letter] = random_list
# Sort by mean of values in descending order
sorted_items = sorted(result_dict.items(), key=lambda item: statistics.mean(item[1]), reverse=True)
# Convert back to dictionary
return dict(sorted_items)
```Test output (stdout)
..... [100%] 5 passed in 0.02s
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.