import queue def GetItemList(q): ret = [] n = q.qsize() while n>0: ret.append(q.get()) n -= 1 return ret l = 'apple,banana,orange' #queue test q = queue.Queue() for x in l.split(','): print(x) q.put(x) print( GetItemList(q) ) #stack case #LIFO last in first out q = queue.LifoQueue() for x in l.split(','): q.put(x) print( GetItemList(q) ) #priorityQueue q = queue.PriorityQueue() q.put((5,"apple")) q.put((10,"banana")) q.put((1,"orange")) print( GetItemList(q) ) """ out put is... ['apple', 'banana', 'orange'] ['orange', 'banana', 'apple'] [(1, 'orange'), (5, 'apple'), (10, 'banana')] """
3/18/2014
Python Study, queue, stack, priority queue, example source code
Subscribe to:
Post Comments (Atom)
-
Google Coral USB Edge TPU Implementation Guide 1. Installation and Troubleshooting 1.1 Hardware Requirements Google Coral USB Accelerator ...
-
Logistic Classifier The logistic classifier is similar to equation of the plane. W is weight vector, X is input vector and y is output...
-
template < int INT> void AAA() { std::cout << "INT = " << INT << std::endl; } How to Call...
-
error: . VanillaPipeline.get_train_loss_dict: 12.6875 Traceback (most recent call last): File "/home/mare/anaconda3...
-
This article is the method about line fitting in 3d points. If we have these 3d points, how to find best 3d line? The main conc...
-
install Claude Code using this shell script . #!/bin/bash # install-claude.sh # Installs Node.js 18+, npm, and Claude Code CLI, handling co...
-
// ============================================================================ // SIMPLE COMPARISON: TUPLE vs VECTOR // When to use which...
-
1. load pre-trained model 2. export onnx 3. load onnx refer to code: . import warnings from torch . jit import TracerWarning warnings . ...
-
refer to code: . from PIL import Image import json import yaml import os import argparse def get_image_dimensions ( image_path ): ...
-
// ============================================================================ // COMPLETE C++ TUPLE TUTORIAL // ==========================...
No comments:
Post a Comment