Question textA more-challenging functionSequences of numbers in which there are frequent "runs" of a particular number repeating several times can often be more compactly represented by use of what is called "run length encoding". A list is run-length encoded by representing it as a list of pairs (2-tuples), where each pair is a number and the length of the "run" of that number, where the length is 1 if a number occurs once, 2 if it occurs twice in a row, etc. Write a function run_length_encode(nums) that returns the run-length encoded representation of the list of integers, nums.For example:[table] Test | Result data = [5, 5, 5, 10, 10] print(run_length_encode(data)) | [(5, 3), (10, 2)] data = [10, 20, 30, 30, 30, 30] print(run_length_encode(data)) | [(10, 1), (20, 1), (30, 4)] [/table] Answer:(penalty regime: 0, 10, 20, ... %)未知题型

登录即可查看完整答案

我们收录了全球超50000道真实原题与详细解析,现在登录,立即获得答案。

类似问题

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!