Tie Python Python List

Asked 2 years ago, Updated 2 years ago, 13 views

I got the whole number as input. If I get 1234567, I want to make a list like [765], [432], [1] Is there a way?

python

2022-09-20 19:37

2 Answers

Please refer to the following

import itertools as it
nums = sorted(range(1, 8), reverse=True)
list(iter(lambda i=iter(nums) : list(it.islice(i, 3)), []))
[[7, 6, 5], [4, 3, 2], [1]]


2022-09-20 19:37

val nums = (1 to 7).reverse
nums.grouped(3).toList

=> List(Vector(7, 6, 5), Vector(4, 3, 2), Vector(1))


2022-09-20 19:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.