-
MathematicsAlgorithmsLogicNumbers
Description PEP 8 - Naming Conventions - Function Names:
Function names should be lowercase, with words separated by underscores as necessary to improve readability.
This naming style is commonly known as
snake_case
.Furthermore, the variable assignment in the previous Kumite is not required; the computed result can be returned immediately.
Finally, as per the Python Test Reference in the official Codewars Docs, the order of arguments for
Test.assert_equals
should beactual, expected
instead of the other way round.Code from itertools import permutations def sequence_permutation(t, n): return list(permutations(t, n))
Test Cases Test.describe("sequence_permutation") Test.it("should correct calculate for permutations with three by three") sq_per_master = sequence_permutation(('a','b','c'), 3) Test.assert_equals(list(sq_per_master[0]), ['a', 'b', 'c']) Test.assert_equals(list(sq_per_master[1]), ['a', 'c', 'b']) Test.assert_equals(list(sq_per_master[4]), ['c', 'a', 'b']) Test.it("should correct calculate for permutations with one item") sq_per_master = sequence_permutation(('a','b','c'), 1) Test.assert_equals(list(sq_per_master[0]), ['a']) Test.assert_equals(list(sq_per_master[1]), ['b']) Test.assert_equals(list(sq_per_master[2]), ['c']) Test.it("should correct calculate for permutations with two items") sq_per_master = sequence_permutation(('a','b','c'), 2) Test.assert_equals(list(sq_per_master[0]), ['a', 'b']) Test.assert_equals(list(sq_per_master[1]), ['a', 'c']) Test.assert_equals(list(sq_per_master[4]), ['c', 'a'])
Output:
-
Code - from itertools import permutations
def SequencePermutation(plenty, count):ret = list(permutations(plenty, count))return ret- def sequence_permutation(t, n):
- return list(permutations(t, n))
Test Cases Test.describe("SequencePermutation")- Test.describe("sequence_permutation")
- Test.it("should correct calculate for permutations with three by three")
- sq_per_master = sequence_permutation(('a','b','c'), 3)
- Test.assert_equals(list(sq_per_master[0]), ['a', 'b', 'c'])
- Test.assert_equals(list(sq_per_master[1]), ['a', 'c', 'b'])
- Test.assert_equals(list(sq_per_master[4]), ['c', 'a', 'b'])
Test.describe("should correct calculate for permutations with three by three")sq_per_master = SequencePermutation(('a','b','c'), 3)Test.assert_equals(['a', 'b', 'c'], list(sq_per_master[0]))Test.assert_equals(['a', 'c', 'b'], list(sq_per_master[1]))Test.assert_equals(['c', 'a', 'b'], list(sq_per_master[4]))- Test.it("should correct calculate for permutations with one item")
- sq_per_master = sequence_permutation(('a','b','c'), 1)
- Test.assert_equals(list(sq_per_master[0]), ['a'])
- Test.assert_equals(list(sq_per_master[1]), ['b'])
- Test.assert_equals(list(sq_per_master[2]), ['c'])
Test.describe("should correct calculate for permutations with one item")sq_per_master = SequencePermutation(('a','b','c'), 1)Test.assert_equals(['a'], list(sq_per_master[0]))Test.assert_equals(['b'], list(sq_per_master[1]))Test.assert_equals(['c'], list(sq_per_master[2]))Test.describe("should correct calculate for permutations with two items")sq_per_master = SequencePermutation(('a','b','c'), 2)Test.assert_equals(['a', 'b'], list(sq_per_master[0]))Test.assert_equals(['a', 'c'], list(sq_per_master[1]))Test.assert_equals(['c', 'a'], list(sq_per_master[4]))- Test.it("should correct calculate for permutations with two items")
- sq_per_master = sequence_permutation(('a','b','c'), 2)
- Test.assert_equals(list(sq_per_master[0]), ['a', 'b'])
- Test.assert_equals(list(sq_per_master[1]), ['a', 'c'])
- Test.assert_equals(list(sq_per_master[4]), ['c', 'a'])
- All
- {{group.name}} ({{group.count}})
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report