UnisKB/apps/common/utils/common.py

39 lines
849 B
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# coding=utf-8
"""
@project: MaxKB
@Author虎虎
@file common.py
@date2025/4/14 18:23
@desc:
"""
import hashlib
from typing import List
def password_encrypt(row_password):
"""
密码 md5加密
:param row_password: 密码
:return: 加密后密码
"""
md5 = hashlib.md5() # 2实例化md5() 方法
md5.update(row_password.encode()) # 3对字符串的字节类型加密
result = md5.hexdigest() # 4加密
return result
def group_by(list_source: List, key):
"""
將數組分組
:param list_source: 需要分組的數組
:param key: 分組函數
:return: key->[]
"""
result = {}
for e in list_source:
k = key(e)
array = result.get(k) if k in result else []
array.append(e)
result[k] = array
return result