迭代元组列表和字典以进行计算(Iterate over tuple list and dictionary to make calc)
Python的新手 - 是否有一种直接的方法来迭代元组列表并使用性能阈值(即每日销售额超过/低于预算销售额)进行计算? 请参阅以下信息:
daily_sales = [('A',150000),('B',73000),('C',110000),('D',231000),('E',66000)] budgeted_sales = {'A':140000,'B':103000,'C':80000,'D':20000,'E':90000} performance_threshold = .20
New to Python - is there a straightforward way to iterate over a tuple list and make a calculation using a performance threshold (i.e., daily sales % over/under budgeted sales)? Please see the info below:
daily_sales = [('A',150000),('B',73000),('C',110000),('D',231000),('E',66000)] budgeted_sales = {'A':140000,'B':103000,'C':80000,'D':20000,'E':90000} performance_threshold = .20
原文:https://stackoverflow.com/questions/35531181
更新时间:2023-07-02 21:07
最满意答案
尝试这个:
async removeItemValue(key) { try { await AsyncStorage.removeItem(key); return true; } catch(exception) { return false; } }
Try this:
async removeItemValue(key) { try { await AsyncStorage.removeItem(key); return true; } catch(exception) { return false; } }
相关问答
更多-
您保存到存储JSON.stringify()值,然后使用它,而不使用JSON.parse() 。 我认为这是问题。 你可以通过在你的List组件渲染器上的断点处停止检查它,然后检测它的道具,并检测你的props.listItems不是componentDidMount之后的数组。 You saved to storage JSON.stringify() values, then used it without using JSON.parse(). I think that this is the pro ...
-
React Native的AsyncStorage可能出现什么故障?(What are the possible failure cases of React Native's AsyncStorage?)[2022-12-05]
代码是开源的,你可以看到调用失败的时候,例如android或者ios 。 getItem调用失败,例如在需要不存在的项时。 其他示例可能是Failed to create storage directory. 您可以在ios模块中看到(例如,当设备上没有足够的空间时)。 The code is open source, you can see when the calls fail, for example here on android or here for ios. The getItem call, ... -
尝试这个: async removeItemValue(key) { try { await AsyncStorage.removeItem(key); return true; } catch(exception) { return false; } } Try this: async removeItemValue(key) { try { await AsyncStorage.removeItem(k ...
-
如果我的理解是正确的,你需要初始化firebase,然后创建一个数据库引用并导出它。 尝试这个: initializeFirebase.js import firebase from 'firebase'; import { AsyncStorage } from 'react-native'; import { FIREBASE_CONFIG, FIREBASE_CONFIG_DEMO, DATA_ENVIRONMENT_STORAGE_KEY } from '../../../s ...
-
一旦从获取请求中获取数据,您就可以将其设置为状态,而不是设置和从异步存储中获取: componentDidMount () { this.fetchProducts() } fetchProducts() { fetch("http://localhost:3000/products",{ method: "GET", headers: { 'Content-Type': 'application/json' }, }) ...
-
我不确定为什么Bergi的建议语法不起作用,但我发现在then语句之前和之后分隔调用和赋值允许严格控制排序,并且返回语句只应返回每次最后一次调用的承诺块。 这可能不是最好的方式,但它对顺序同步读取似乎很有效。 AsyncStorage.getItem("v1") .then( (value) => { this.setState({v1:value}) return AsyncStorage.getItem("v2") } ) .then( (valu ...
-
如何使用AsyncStorage React Native缓存API数据(How to Cache API data using AsyncStorage React Native)[2021-12-05]
async componentDidMount() { const photoStorage = await AsyncStorage.getItem('GalleryPhotos') if(photoStorage) { try { const photoResp = await axios.get('http://jsonplaceholder.typicode.com/photos') const photoData = await JSON ... -
如何使用React Native中的AsyncStorage multiGet检索数据(How to retrieve data with AsyncStorage multiGet in React Native)[2022-03-14]
它的工作原理如下,因为它提供了嵌套的数组响应 该数组包含键作为index 0和值作为index 1 AsyncStorage.multiGet(["@BarcodeList", "@ScannedBarcode"]).then(response => { console.log(response[0][0]) // Key1 console.log(response[0][1]) // Value1 console.log(respo ... -
AsyncStorage是异步的,因此在检索到它所寻找的内容之前不会定义data_url,你需要将fetch移动到get中返回的promise中,这样它一旦获取数据就会运行它。 这可能是解决问题的一种方法: const data_url = () => AsyncStorage.getItem("data_url"); //change this into a function module.exports = { url: data_url, ..... } 现在你的组件里面..... ...
-
AsyncStorage是一个简单的,未加密的,异步的,持久的键值存储系统,对应用程序来说是全局的。 它应该用来代替LocalStorage。 当你想在App中全局使用某个变量时,它会被使用。 例如,当您第一次在应用程序中登录时,商店会显示登录ID和密码,以便下次从AsyncStorage获取数据并成功登录。 请参阅此链接 AsyncStorage is a simple, unencrypted, asynchronous, persistent, key-value storage system tha ...