帮我制作这个节目 [英] Help me make this program

查看:83
本文介绍了帮我制作这个节目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个Python函数频率(l),它将整数列表作为输入,并返回一对形式(minfreqlist,maxfreqlist),其中

minfreqlist是一个最小频率的数字列表l,按升序排序

maxfreqlist是最大频率为l的数字列表,按升序排序

例如

>> ;>频率([13,12,11,13,14,13,7,11,13,14,12])

([7],[13])



>>>频率([13,12,11,13,14,13,7,11,13,14,12,14,14])

([7],[13,14])< br $> b $ b

>>>频率([13,12,11,13,14,13,7,11,13,14,12,14,14,7])

([7,11,12],[ 13,14])



我尝试了什么:



我我试过为它制作一个程序...哪些不能正常工作...请帮助

Write a Python function frequency(l) that takes as input a list of integers and returns a pair of the form (minfreqlist,maxfreqlist) where
minfreqlist is a list of numbers with minimum frequency in l, sorted in ascending order
maxfreqlist is a list of numbers with maximum frequency in l, sorted in ascending
For instance
>>> frequency([13,12,11,13,14,13,7,11,13,14,12])
([7], [13])

>>> frequency([13,12,11,13,14,13,7,11,13,14,12,14,14])
([7], [13, 14])

>>> frequency([13,12,11,13,14,13,7,11,13,14,12,14,14,7])
([7, 11, 12], [13, 14])

What I have tried:

I have tried making a program for it...which din't work properly...please help

推荐答案

首先计算每个值的出现次数。您还需要一些方法来存储此信息,因此请查看可以以这种方式将两个值保持在一起的集合类型:可能是字典。获得该信息后,您可以找到最小和最大出现次数。一旦你有了这两个值,你就可以通过集合制作一个列表,列出所有值最小的值,以及所有那些最大值。
Start by counting the number of occurrences of each value. You also need some way to store this information, so look at the collection types that can keep two values together in this way: maybe a dictionary. Once you have that information you can find the minimum and maximum occurrences. And once you have those two values you can go through the collection making a list of all the values with minimum count, and all those with maximum.


我不会告诉你解决方案但我可以给你一个提示。



**将该列表转换为键值对。其中key是列表中的元素,value是元素的数量。



这样可以创建一个包含元素及其相应频率的唯一字典。
I am not going to tell you the solution But I can give you a hint.

** Turn that list into a key-value pair. Where key is the element in the list and value is the count of the elements.

This works as you can make a unique dictionary containing just the elements and their corresponding frequency.


我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。

因此,如果您尝试过,那么您的代码可能存在一个小问题 - 对此你需要调试器。



亲自尝试一下,你可能会发现它并不像你想象的那么难!



如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
So if you've tried, you have code with maybe a small problem - for that you need the debugger.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


这篇关于帮我制作这个节目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆