Interview Query

Split Data Without Pandas

Have you seen this question before?

You are given a string that resembles the declaration of a list of dictionaries. Without using pandas, write a function read_split_from_str that:

  1. Reads the data and encodes it as a list of dictionaries
  2. Split the data into two lists, one for training and one for testing, with a 70:30 split between the training set and the testing set. Use numpy for random number generation if you need. Return a list of [training_set,testing_set]



list_of_dict_string = "[{'x': 0.0, 'y': 5.43}, {'x': 50.0, 'y': 102.78}, {'x': 100.0, 'y': 204.24}]"


def read_split_from_str(list_of_dict_string) -> 
    [{'x': 0.0, 'y': 5.43}, {'x': 50.0, 'y': 102.78}],
    [{'x': 100.0, 'y': 204.24}]
Next question: Weekly Aggregation
Python 3.9.6
Loading editor
Use Shift + Enter to run code