Question
The goal is to find a simple way for converting a set of data to a string.
Maybe I am too newby but I found nothing about conversion from a set to string. A similar question (Numpy converting array from float to strings) did not help me a lot.
Example
The code I wrote seems definitely not ideal:
DataSet = {(1,4): 272.3, (2,4): 274.74} print(', '.join(np.array(DataSet).astype('str')))) Personal goal
In the end I want to create a string like:
DataSet = {(1,4): 272.3, (2,4): 274.74} version = 2.7 print(''.join(np.array(['The data in {', ', '.join(np.array(DataSet).astype('str'))), '} is calculated with python%3.1f.' % version])) The output should look like (it would be nice but not necessary to implement some fixed float precision):
'The data in {272.3, 274.7} is calculated with python2.7.'
', '.join(str(i) for i in DataSet.items())? how aboutstr(dataSet)? Do you actually need to convert the individual elements, or do you only need a single string output (and if the latter, what's the desired output format for the dict?)?'((2, 4), 274.74), ((1, 4), 272.3)', and the second one:'{(2, 4): 274.74, (1, 4): 272.3}'. I did not expect the index to be printed too - but it makes sense in most cases! Do we call the structure ofDataSetset or dictionary? @late_riser: I hope having clarified the desired output.