Skip to content Skip to sidebar Skip to footer

Convert Dictionary To List Of Float-element

I want to convert this dictionary to a list of float elements. I have some code, but I don't know how to achieve this. The .csv file I have consists of both number and words. The n

Solution 1:

You're going to have to explain what your input currently looks like and what your desired output should look like.

If I understand the question, you want to create a list of floats from the values in the dictionary? If so, all you need to do is a simple list comprehension using the values of the dictionary.

float_elements = [float(val) for val indict.values()]

Solution 2:

If you want a dict into a list with key and value, this is an option.

import csv
defload_csv (filename):
  withopen (filename, 'r')as f:
  reader = f.readlines()
  result = []
  for row inenumerate(reader):
      result.append(row)
      print(result)

Post a Comment for "Convert Dictionary To List Of Float-element"