当前位置:网站首页>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
边栏推荐
- Analysis and cleaning of kdevtmpfsi virus content
- The correct way to clear the cache of the computer. The computer will not get stuck immediately after changing. practical
- MySQL is slow to add indexes_ Why is your SQL so slow? Why is your MySQL index invalid?
- Decryption of APP parameters of a cross-border export e-commerce - dunhuang.com
- PHP compressed file
- JS__ Inheritance mode, namespace, object enumeration__ Duyi
- Win10 common software
- Cross project measurement is a good helper for CTOs and PMOS
- [nailing scenario capability package] smart office phone
- Must see the summary! In depth learning era, you should read 10 articles to understand image classification!
猜你喜欢
![[nailing scenario capability package] video conference (official conference system)](/img/ec/c2f342a54ab69d8b834a8a1c8f8a01.jpg)
[nailing scenario capability package] video conference (official conference system)
Tencent music knowledge map search practice

Heavy update! Yolov4 latest paper! Interpreting yolov4 framework
Section 13: simplify your code with Lombok
![[nailing - scenario capability package] nailer card](/img/ec/c2f342a54ab69d8b834a8a1c8f8a01.jpg)
[nailing - scenario capability package] nailer card

Jingxi Pinpin wechat applet -signstr parameter encryption
Cross project measurement is a good helper for CTOs and PMOS

Get parameters in URL

04 disk space management

Molecular dynamics - basic characteristics of molecular force field
随机推荐
Is it safe for Xiaobai to open a stock account online?
OLED driver learning based on ssd1306 (I): SSD Chinese command table (handling)
Is it safe to fry stocks with compass or securities software? Where can I open an account and how
Section 13: simplify your code with Lombok
JS__ This, arguments, cloning, ternary operator__ Duyi
同花顺app是正规的吗?到底安不安全
UDP Vs TCP (Powercert animated videos)
Installing and configuring redis under Linux
Bank digital transformation layout in the beginning of the year, 6 challenges faced by financial level structure and Countermeasures
Illustration tcp/ip - Chapter 3 and 4 notes
C language soul torture: do you know the difference between the two?
On merging and sorting
Support JPEG format in GD Library in php7.4
Rounding related calculation
Desktop network error display red ×, Component failed to start
Compile 6relayd using the cross compiler
[distributed system design profile (1)] raft
MySQL operation Basics
2022年启牛学堂证券开户安全嘛?
The user name and password will be automatically filled in when adding a form