Midterm(repeat)

A MathWikiből

Tartalomjegyzék

Programming Problems:

Problem 1

Write a function which input is a list containing strings and the output is a dictionary, where the keys are the elements of the list and the values are the index of the corresponding elements.

Problem 2

Write a function which calculates the least common multiple of two positive natural numbers. (Hint: Use while cycle.)

Problem 3

D is a dictionary, where the keys are letters from the english alphabet, and the values are numbers in string format. Write a function which input is a dictionary like that and the output is a dictionary, which has two keys: "vowel", "consonant" and the values are the sum of the values of the corresponding letters in string format. For example:

     If D = { 'a' : '5', 'b' : '2', 'c' : '3', 'e' : '5' }, 
     then it returns:
     { "vowel" : '10', "consonant" : '5' }

(Hint: We consider a, e, i, o, u as vowels.)

Problem 4

Write a Python program to create a list reflecting the run-length encoding from a given list of integers or a given list of characters.

Run-length encoding (RLE) is a form of lossless data compression in which runs of data (sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run. For example:

'aaabaaa' --> [[3, 'a'], [1, 'b'], [3, 'a']]
'babaaaa' --> [[1, 'b'], [1, 'a'], [1, 'b'], [4, 'a']]
'bbbbbbbbbb' --> [ [10, 'b'] ]
Személyes eszközök