Python random.shuffle function/list/tuple TypeError: 'NoneType' object is not usable

Asked 2 years ago, Updated 2 years ago, 149 views

Hello!

While I was working on this and that with what I learned, I thought I could randomly extract two lists at once and make a code, but in the A=tuple(a) step, it said TypeError: 'NoneType' object is impossible' and I'm looking for a master who can explain why. Thank you very much for your reply in advance!

import random

data1 = ["Ga", "Na", "Da", "La"]

data2 = ['a','b','c','d']


a= random.shuffle(data1)

b= random.shuffle(data2)


A= tuple(a)
dic = {A:b}


print(dic)

random tuple list

2022-09-20 08:42

1 Answers

import random

data1 = ["Ga", "Na", "Da", "La"]
data2 = ['a','b','c','d']

random.shuffle(data1)
random.shuffle(data2)

dic = {a: b for a, b in zip(data1, data2)}
print(dic)

I think it'd be good to do it like this.


2022-09-20 08:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.