当前位置:网站首页>Common singleton functions traverse dictionary functions
Common singleton functions traverse dictionary functions
2022-06-25 21:19:00 【Strange meow】
def singleton(cls):
_instance = {}
def _singleton(*args, **kwargs):
if cls not in _instance:
_instance[cls] = cls(*args, **kwargs)
return _instance[cls]
return _singleton
def get_dict(dict1, obj, default=None):
""" Traverse nested dictionaries , Get what you want value
dict1 Dictionary to traverse
obj what is needed value Key """
for k, v in dict1.items():
if k == obj:
return v
else:
if type(v) is dict: # If it's a dictionary
re = get_dict(v, obj, default) # recursive
if re is not default:
return re
边栏推荐
- Beginner to embedded development
- A simple file searcher
- Analysis and cleaning of kdevtmpfsi virus content
- Working principle and experimental analysis of DHCP
- [nailing scenario capability package] ranking of enterprise employees' points
- Send a more awesome website, which can convert curl commands into code in any language
- JS__ Prototype, prototype chain, call/apply__ Duyi
- [summary] 2021unctf Campus (cry & MISC)
- What is a subnet mask? (Powercert animated videos)
- Rounding related calculation
猜你喜欢
Boomfilter learning

On ACM competition
![[buucry] sensor (Manchester code)](/img/ab/066923f1aa1e8dd8dcc572cb60a25d.jpg)
[buucry] sensor (Manchester code)
Yunzhisheng atlas supercomputing platform: computing acceleration practice based on fluid + alluxio (Part 2)

Vbpr (visual Bayesian personalized ranking) paper summary

js (1)

The difference between strcpy and memcpy

CANoe. Diva operation guide TP layer test

Volatile qualifier

Idea implements hot deployment
随机推荐
Working principle and experimental analysis of DHCP
JVM Foundation
[nailing - scenario capability package] nailer card
Summary of several methods for FPS calculation
XMIND to excel test case
PHP compressed file
Yolov4 reading notes (with mind map)! YOLOv4: Optimal Speed and Accuracy of Object Detection
ZABBIX foundation details
Lesson 3 urllib
Docker failed to remotely access 3306 after installing MySQL
Nmap is simple and practical
STM32 self balancing robot project, with code, circuit diagram and other data attached at the end (learning materials and learning group at the end)
What is a server? (Powercert animated videos)
Get the root directory of the package at compile time from buildreoot
Compile 6relayd using the cross compiler
Shell syntax
[phase 23] phased summary of spring recruitment practice (Alibaba cloud has OC)
Support JPEG format in GD Library in php7.4
Installing and configuring redis under Linux
Heavy update! Yolov4 latest paper! Interpreting yolov4 framework