How to save separated values from a list of numbers

  • i want to recibe a list of values(numbers in this case) in a key called "sensor_data" and save those values separated but i couldnt figureout how to make this function without using another framework.
@api_view(['POST'])
def saveData(request):
    
    values_list = []
    separated_values = values_list.split(',')
    sensor_data = {'sensor_data' : values_list }
    print (sensor_data)
    return Response() 

You can use below to create list of tuples using your dictionary;

d = { 'a': 1, 'b': 2, 'c': 3 }
new_d = list(d.items())

print(new_d)

EDIT:

You can define a function like below to get input from user and assign it to dictionary that you can later use;

def sensor_input():
    user_input = input("please provide a series of numbers (example: 1,2,3,4)")
    input_list = list(user_input.split(","))
    sensor_data ={"input_values" : input_list}
    print(sensor_data)
    return sensor_data

sensor_input()

Output :

{'input_values': ['1', '2', '3', '4']}
Back to Top