6 kyu

Sort My Animals

506 of 2,609GrahamD

Description:

Consider the following class:

  public class Animal
  {
    public string Name { get; set; }
    public int NumberOfLegs { get; set; }
  }
var Animal = { 
    name: "Cat", 
    numberOfLegs: 4 
}
class Animal:
    def __init__(self, name, number_of_legs):
        self.name = name
        self.number_of_legs = number_of_legs

Write a method that accepts a list of objects of type Animal, and returns a new list. The new list should be a copy of the original list, sorted first by the animal's number of legs, and then by its name.

If an empty list is passed in, it should return an empty list back.

Lists
Sorting
Fundamentals

More By Author:

Check out these other kata created by GrahamD

Stats:

CreatedApr 25, 2017
PublishedMay 2, 2017
Warriors Trained4878
Total Skips137
Total Code Submissions11508
Total Times Completed2609
C# Completions506
JavaScript Completions1613
Python Completions536
Total Stars60
% of votes with a positive feedback rating93% of 512
Total "Very Satisfied" Votes449
Total "Somewhat Satisfied" Votes51
Total "Not Satisfied" Votes12
Total Rank Assessments19
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • GrahamD Avatar
  • smile67 Avatar
  • Blind4Basics Avatar
  • dcieslak Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • KayleighWasTaken Avatar
  • brodiemark Avatar
Ad