I am trying to create a deque of strings, but when I add a string to the deque it always breaks the string up into individual characters. Here is my code so far:
from collections import deque
my_string = "test"
my_queue = deque(my_string)
print my_queue
The output I get is:
deque(['t', 'e', 's', 't'])
I would like the output to be:
deque(['test'])
Any thoughts?
ConcurrentLinkedDeque is a lock-free implementation of Deque interface. This implementation is completely thread-safe as it uses an efficient lock-free algorithm.
Deques support indexing, but interestingly, they don't support slicing.
First, define a string. Next, create a for-loop where the loop variable will start from index 0 and end at the length of the given string. Print the character present at every index in order to separate each individual character. For better visualization, separate each individual character by space.
The deque constructor takes an iterable as a parameter, if you just give the string to it, it will interpret it as a sequence of characters.
In order to do what you want you should wrap your string into a list:
your_string = 'string'
wrap_list = [your_string]
#Now create the deque
d = deque(wrap_list)
Of course you can do everything in one step:
your_string = 'string'
d = deque([your_string])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With