In: Computer Science
# Otherwise, a line contains a blues musician. In this case,
process the record much as you did above,
# except that you also need to add a musical style to the tuple as
the third element.
# These data should be appended to the list `entries` as a single
entry in the form of a tuple,
# (surname, first_name, current_style)
# Finally, `return` the list `entries`.
The input is from a txt file
# it should pass this test
# test basic single-genre case
zydeco = process('./data/zydeco.txt')
assert zydeco[0] == ('Chavis', 'Boozoo', 'Zydeco')
assert zydeco[-3] == ('Dopsy', "Rockin'", 'Zydeco')
file zydeco.txt:
#Zydeco
Boozoo Chavis
C. C. Adcock
Chris Ardoin
Scott Billington
Dudley Broussard
Chubby Carrier
Roy Carrier
C. J. Chenier
Chubby Carrier
Geno Delafose
Canray Fontenot
Keith Frank
Queen Ida
Beau Jocque
Leftover Salmon
Rockin' Sidney
Terrance Simien
Andre Thierry
Cedric Watson
Buckwheat Zydeco
Nathan Williams
Guyland Leday
Lil' Nate
Leon Chavis
Mo' Mojo
Kenne' Wayne
Rockin' Dopsy
Amede Ardoin
Clifton Chenier
RAW CODE
def process(filename):
a = open(filename,"r")
b = a.readlines() ### read line by line until \n character
words = [x.strip() for x in b] ### remove \n character
words = [x for x in words if x] ### In case list have null value, then remove
data = []
for word in words:
if word[0] == '#':
music_type = word[1:] ## If starts with # then keep it as music type
else:
*first, last = word.split(" ") ### * indicates more than one value
tup = (last, " ".join(first), music_type) ## making them tuples
data.append(tup) ### appending tuple in list
return data
zydeco = process('zydeco.txt')
assert zydeco[0] == ('Chavis', 'Boozoo', 'Zydeco')
assert zydeco[-3] == ('Dopsy', "Rockin'", 'Zydeco')
print(zydeco)
SCREENSHOTS (CODE WITH OUTPUT)
##### FOR ANY QUERY, KINDLY GET BACK, THANKYOU. #####