Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercise: collect packets

  • You get a series of packets (e.g. lines in a file)
  • In each line you have several fields: id, seqid, maxseq, content
  • id is a unique identifier of a series of packets (lines)
  • seqid is the seuence id of a packet in a series. (an integer)
  • maxseq is the length of the sequence.
  • content is the actual content.

In each iteration return a message that is built up from all the packages in the given sequence.

12,1,5,First of Twelve
12,2,5,Second of Twelve
12,3,5,Third of Twelve
12,4,5,Fourth of Twelve
12,5,5,Fifth of Twelve

9,1,4,First of Nine
9,2,4,Second of Nine
9,3,4,Third of Nine
9,4,4,Fourth of Nine

11,1,3,First of Eleven
11,2,3,Second of Eleven
11,3,3,Third of Eleven

Output:

['First of Twelve', 'Second of Twelve', 'Third of Twelve', 'Fourth of Twelve', 'Fifth of Twelve']
['First of Nine', 'Second of Nine', 'Third of Nine', 'Fourth of Nine']
['First of Eleven', 'Second of Eleven', 'Third of Eleven']
12,1,5,First of Twelve
11,1,3,First of Eleven
9,1,4,First of Nine
12,2,5,Second of Twelve
9,2,4,Second of Nine
11,2,3,Second of Eleven
12,3,5,Third of Twelve
9,3,4,Third of Nine
12,4,5,Fourth of Twelve
12,5,5,Fifth of Twelve
9,4,4,Fourth of Nine
11,3,3,Third of Eleven
11,2,3,Second of Eleven
11,1,3,First of Eleven
9,1,4,First of Nine
12,1,5,First of Twelve
9,3,4,Third of Nine
9,2,4,Second of Nine
12,3,5,Third of Twelve
12,4,5,Fourth of Twelve
12,2,5,Second of Twelve

12,5,5,Fifth of Twelve
9,4,4,Fourth of Nine
11,3,3,Third of Eleven