How to use 'python list sample' in Python

Every line of 'python list sample' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
419def sample_as_list(sample):
420 """Return sample object in list format.
421
422 Args:
423 sample (list/dict/dimod.SampleView): Sample object formatted as a list,
424 Numpy array, dict, or as returned by dimod samplers. Variable labeling
425 must be numerical.
426
427 Returns:
428 list: Copy of `sample` formatted as a list.
429
430 Examples:
431 >>> sample = {0: 1, 1: 1}
432 >>> sample_as_list(sample)
433 [1, 1]
434
435 """
436 if isinstance(sample, list):
437 return sample
438 if isinstance(sample, numpy.ndarray):
439 return sample.tolist()
440 indices = sorted(dict(sample).keys())
441 if len(indices) > 0 and indices[-1] - indices[0] + 1 != len(indices):
442 raise ValueError("incomplete sample dict")
443 return [sample[k] for k in indices]
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code


Related snippets