code: def sample(data, sample_rate):
          
          if sample_rate >= 1:
              return data
          elif sample_rate < 1:
              if random() <= sample_rate:
                  sampled_data = {}
                  for stat, value in data.items():
                      sampled_data[stat] = "{0}|@{1}".format(value, sample_rate)
                  return sampled_data
          return {}
docs: Sample data dict
          TODO(rbtz@): Convert to generator
  
          >>> StatsdClient.sample({"example.sample2": "2"}, 1)
          {'example.sample2': '2'}
          >>> StatsdClient.sample({"example.sample3": "3"}, 0)
          {}
          >>> from random import seed
          >>> seed(1)
          >>> StatsdClient.sample({"example.sample5": "5",
          ... "example.sample7": "7"}, 0.99)
          {'example.sample5': '5|@0.99', 'example.sample7': '7|@0.99'}
          >>> StatsdClient.sample({"example.sample5": "5",
          ... "example.sample7": "7"}, 0.01)
          {}