I'm printing the initials of a randomly generated piece of data from my csv file and trying to print the piece of data from row[1] that accompanies it but I can't seem to get it to work. Only the first piece of data in row [1] is printed (Lizzo).
with open ("songs.csv") as songlist:
songReader = csv.reader(songlist, delimiter = ',')
for row in songReader:
songNames = list(songReader)
randomSong = random.choice(songNames)
text = randomSong[0]
text = (''.join([s[:1] for s in text.split(' ')])) + row[1]
print(text)
CSV file:
Truth Hurts, Lizzo
Goodbyes, Post Malone
Circles, Post Malone
Bad Guy, Billie Eilish
Ran$om, Lil Tecca
No Guidance, Chris Brown
Take What You Want, Post Malone
Someone You Loved, Lewis Capaldi
Sunflower, Post Malone
Talk, Khalid
I expected for example: S Post Malone (S standing for Sunflower) but I get S Lizzo
Aucun commentaire:
Enregistrer un commentaire