0

I have a deque full of integer and I would like to build a string (or just print it) in hexadecimal format.

I tried

from collections import deque

a = deque([10,11])
my_string = hex(a)

It says that deque can't be interpreted as an integer. I would like something like :

deque([0xA, 0xB])
pault
  • 41,343
  • 15
  • 107
  • 149
Welgriv
  • 714
  • 9
  • 24
  • 4
    so `deque(map(hex, a))`? Your desired output is invalid (missing the quotes). – pault Jul 31 '19 at 14:57
  • Why do you not build the string then? Copy the deque into a list, build a list of its hex representations and print it... – Patrick Artner Jul 31 '19 at 14:57
  • @pault: You should give that as an answer. Perhaps include converting your answer to a string and removing all the single quotes, to completely match the OP's format--I do see some possible uses for that format. – Rory Daulton Jul 31 '19 at 15:01
  • @RoryDaulton I don't know - should it be closed as a dupe of [this](https://stackoverflow.com/questions/10973766/understanding-the-map-function) or [this](https://stackoverflow.com/questions/25082410/apply-function-to-each-element-of-a-list) instead? – pault Jul 31 '19 at 15:07
  • @pault: I don't think so, since those other questions are much more general. This question does not mention `map` at all. – Rory Daulton Jul 31 '19 at 15:09
  • @RoryDaulton moot point anyway since OP answered their own question. – pault Jul 31 '19 at 15:13

1 Answers1

1

pault comment's answer :

    >>> deque(map(hex, a))
deque(['0xa', '0xb'])
Welgriv
  • 714
  • 9
  • 24