程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python will get an average LOC after using fitter. How can I output this average LOC

編輯:Python

Python Use fitter Then you will get an average loc, How can I output this mean loc




Take the answer :

The two methods , I just learned it secretly

# Character decomposition method import re # Import re# Suppose this is yours filter The dictionary after dict_goal = {
'lognorm': {
's': 0.17754071946201297, 'loc': 0.04714525287344861, 'scale': 0.0027848854527136027}}def get_loc(dict_you_want): # Write a small method , The entry is the dictionary you want to deal with  res = float(re.findall(r"\'loc\': \d*.\d*", str(dict_you_want), re.DOTALL)[0].strip("'loc': ")) # float() Is the character str Convert to float, That is, the number with decimal point  # re.findall( The characteristics of the content you are looking for , In which strings ,re.DOTALL) re.DOTALL Indicates that each character to be read includes \n etc.  # among \' Indicates English single quotation marks \d Represents numeric characters . Means any character * It means to follow 0 To infinite congeners , such as \d* The length is 0 To infinite number string , It can be used to find 0.04714525287344861 # strip() You can remove the specified characters at both ends , For example, we can remove loc Mark , Just pure numbers  return res # The export is extracted float The number way_A = get_loc(dict_goal)# print(way_A) The result is that 0.04714525287344861# The normal way way_B = dict_goal['lognorm']['loc'] # filter after , The result is a big dictionary with a small dictionary , Then let's set two key Can also extract # print(way_B) The result is that 0.04714525287344861


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved