I need to make a single tuple out of dictionary.
So, I have the following dictionary:
dict = {'n_estimators': 300, 'min_samples_split': 10, 'min_samples_leaf': 3, 'max_features': 'auto', 'max_depth': 15, 'bootstrap': True}
I need to find a command which will return a tuple with the "=" sign instead of ":". In other words, I need to turn the keys of a dictionary to the variables and assign to them the corresponding values from dictionary.
So the output should be the following:
tuple_from_dict = (n_estimators=300, min_samples_split=10, min_samples_leaf=3, max_features= 'auto', max_depth= 15, bootstrap= True)
I tried this code:
# Initialization of dictionary
dict = {'n_estimators': 300, 'min_samples_split': 10, 'min_samples_leaf': 3, 'max_features': 'auto', 'max_depth': 15, 'bootstrap': True}
# Converting into list of tuple
list = [(k, v) for k, v in dict.items()]
# Printing list of tuple
print(list)
But this code creates a tuple of tuples, separated by comma.
I also saw this question, but I am looking for the way to do it more simple. I am new to python, so please don't be very mad at a possibly stupid question.
Do you, guys, know how to fix that?
UPDATE: Based on the discussion below, it is possible to create a namedtuple out of dictionary. But is there any way to make a simple tuple? Or to get rid of a name in a namedtuple to create a simple tuple?