如何获取数组中的前N个元素

时间:2018-11-06 13:16:16

标签: javascript

假设您有一个数组def sortAnimal(llist): while True: print("\nChoose which parameter to sort: \n") print("1. Name\n2. Age\n3. Species\n") choice = int(input("Choice:")) print("\n") choices = {1: lambda animal: animal.name, 2: lambda animal: animal.age, 3: lambda animal: animal.species} print("{:7s} {:7s} {:7s} {:7s}".format("Name:", "Age:", "Species:", "Gender:")) sortedList = sorted(llist, key=choices[choice]) for obj in sortedList: print(obj) if input("\To reverse the list press enter. Otherwise press m + enter") == "": print("\n") print("{:7s} {:7s} {:7s} {:7s}".format("Name:", "Age:", "Species:", "Gender:")) sortedList = sorted(llist, key=choices[choice], reverse=True) for obj in sortedList: print(obj) else: pass if input("\To sort again press enter, back to menu press m + enter") == "": continue else: break ,并且必须输出一个包含键-值对(其中键代表元素,值代表频率)的对象的排序数组,例如...

x = [1, 1, 2, 2, 2, 3]

...什么是最优雅的方式?

1 个答案:

答案 0 :(得分:1)

您可以创建一个临时对象并执行简单的@Bean EmbeddedServletContainerCustomizer containerCustomizer() throws Exception { return (ConfigurableEmbeddedServletContainer container) -> { if (container instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container; tomcat.addConnectorCustomizers( (connector) -> { connector.setMaxPostSize(10000000); // 10 MB } ); } }; } 并检查对象中是否存在当前数字作为键,如果为true则将值加1,否则创建该键,然后使用简单的.forEach添加新数组中单独对象中的所有键值对

.map