-1

I have a dict:

A = {'serial1': 'x1', 'serial2': 'x2', 'serial3': 'x3', 'serial4': 'x5', 'serial5': 'x5'}```

How can I get only the value of each keys? I only want to retrieve the value and remove the key.

Expected Output:

A = {'x1',  'x2',  'x3', 'x5', 'x5'}

terry5546
  • 111
  • 2
  • 10
  • 3
    Does this answer your question? [How can I get list of values from dict?](https://stackoverflow.com/questions/16228248/how-can-i-get-list-of-values-from-dict) – Art Oct 03 '21 at 17:22
  • 2
    `A.values()` ?? – balderman Oct 03 '21 at 17:22
  • 1
    The expected output should be `A = ['x1', 'x2', 'x3', 'x5', 'x5']` (note the square brackets `[]`), because dictionaries _must_ have keys. What you want is a list. – Sylvester Kruin Oct 03 '21 at 17:23

1 Answers1

2
B = A.values()
print(B)

>>> ['x1', 'x2', 'x3', 'x5', 'x5']
B = [item[1] for item in A.items()]
print(B)

>>> ['x1', 'x2', 'x3', 'x5', 'x5']
cavalcantelucas
  • 1,362
  • 3
  • 12
  • 34