I want to make a playlist generator, I have a list containing different songs and I want to generate a random numbered list from it containing only 10 items, and this is the code I tried:
import random
a = ['Bruised and Scarred - Mayday Parade',
'Miracles in December - EXO',
'All Too Well - Taylor Swift',
'Gravity - Sara Bareilles',
'Perfectly Perfect - Simple Plan',
'Welcome To The Black Parade - My Chemical Romance',
'Everything Has Changed - Taylor Swift',
'Champagne - Taylor Swift',
'Piece of Your Heart - Mayday Parade',
'Blame It On The Rain - He Is We',
'Sad Song - We The Kings',
'Give It All - He Is We',
]
for x in range(1, 11):
for y in random.sample(a, k=10):
print(str(x) + y)
but I got this output:
1Bruised and Scarred - Mayday Parade
1All Too Well - Taylor Swift
1Blame It On The Rain - He Is We
1Everything Has Changed - Taylor Swift
1Give It All - He Is We
1Miracles in December - EXO
1Perfectly Perfect - Simple Plan
1Gravity - Sara Bareilles
1Sad Song - We The Kings
1Piece of Your Heart - Mayday Parade
2All Too Well - Taylor Swift
2Bruised and Scarred - Mayday Parade
2Blame It On The Rain - He Is We
2Perfectly Perfect - Simple Plan
2Champagne - Taylor Swift
2Everything Has Changed - Taylor Swift
2Piece of Your Heart - Mayday Parade
2Miracles in December - EXO
2Welcome To The Black Parade - My Chemical Romance
2Give It All - He Is We
3Bruised and Scarred - Mayday Parade
3Gravity - Sara Bareilles
3Welcome To The Black Parade - My Chemical Romance
3All Too Well - Taylor Swift
3Perfectly Perfect - Simple Plan
3Sad Song - We The Kings
3Champagne - Taylor Swift
3Everything Has Changed - Taylor Swift
3Piece of Your Heart - Mayday Parade
3Give It All - He Is We
4Everything Has Changed - Taylor Swift
4Blame It On The Rain - He Is We
4Piece of Your Heart - Mayday Parade
4Gravity - Sara Bareilles
4Bruised and Scarred - Mayday Parade
4Welcome To The Black Parade - My Chemical Romance
4Miracles in December - EXO
4Sad Song - We The Kings
4Give It All - He Is We
4Perfectly Perfect - Simple Plan
5Gravity - Sara Bareilles
5Blame It On The Rain - He Is We
5Perfectly Perfect - Simple Plan
5Champagne - Taylor Swift
5Everything Has Changed - Taylor Swift
5Bruised and Scarred - Mayday Parade
5Welcome To The Black Parade - My Chemical Romance
5All Too Well - Taylor Swift
5Give It All - He Is We
5Miracles in December - EXO
6Bruised and Scarred - Mayday Parade
6Champagne - Taylor Swift
6Everything Has Changed - Taylor Swift
6Miracles in December - EXO
6Welcome To The Black Parade - My Chemical Romance
6Sad Song - We The Kings
6All Too Well - Taylor Swift
6Gravity - Sara Bareilles
6Give It All - He Is We
6Perfectly Perfect - Simple Plan
7Gravity - Sara Bareilles
7Sad Song - We The Kings
7Everything Has Changed - Taylor Swift
7Welcome To The Black Parade - My Chemical Romance
7Piece of Your Heart - Mayday Parade
7Blame It On The Rain - He Is We
7Bruised and Scarred - Mayday Parade
7Give It All - He Is We
7Champagne - Taylor Swift
7All Too Well - Taylor Swift
8Sad Song - We The Kings
8Gravity - Sara Bareilles
8Champagne - Taylor Swift
8Blame It On The Rain - He Is We
8Miracles in December - EXO
8Give It All - He Is We
8Welcome To The Black Parade - My Chemical Romance
8Bruised and Scarred - Mayday Parade
8Piece of Your Heart - Mayday Parade
8Everything Has Changed - Taylor Swift
9Gravity - Sara Bareilles
9Champagne - Taylor Swift
9Bruised and Scarred - Mayday Parade
9Blame It On The Rain - He Is We
9Piece of Your Heart - Mayday Parade
9Everything Has Changed - Taylor Swift
9Sad Song - We The Kings
9Welcome To The Black Parade - My Chemical Romance
9All Too Well - Taylor Swift
9Perfectly Perfect - Simple Plan
10Champagne - Taylor Swift
10Blame It On The Rain - He Is We
10Perfectly Perfect - Simple Plan
10Miracles in December - EXO
10Give It All - He Is We
10Piece of Your Heart - Mayday Parade
10Everything Has Changed - Taylor Swift
10Welcome To The Black Parade - My Chemical Romance
10Bruised and Scarred - Mayday Parade
10Sad Song - We The Kings
I want it to contain only 10 items, but I got way too many, could please help me (Sorry for my bad english)
Aucun commentaire:
Enregistrer un commentaire