160k views
0 votes
We will extend this idea to streams. Write a function called rle that takes in a stream of data, and returns a corresponding stream of two-element lists, which represents the run

User Joe Abrams
by
6.1k points

1 Answer

0 votes

Answer:

def rle(data_stream ):

with open( "data_stream" ) as file:

container= [ ]

two_itemlist= [ ]

while True:

container.append( file.readlines )

file.close( )

while container == True:

value= container.pop(0)

split_value= value.split( " " )

while split_value == True:

while len( two_itemlist) < 2:

holder = split_value.pop( 0 )

two_itemlist.append( holder )

yield two_itemlist

new_list = rle ( new_file )

Step-by-step explanation:

In the solution above, the defined function is a generator, as it continuously returns a two-element list.

User Strillo
by
6.5k points