key-value

subtract array values from each other creating new array

偶尔善良 提交于 2019-12-25 02:27:09
问题 On my site I have the following code, which grabs values from a form and creates a text file with a list of my image paths and duration times. -- /* This is for looping through the uploaded pictures and sorting them and creating a text file. */ $vid_pix = get_post_meta($v_Id, 'vid_pix', false); $data = "ffconcat version 1.0"; $line = ''; usort( $vid_pix, function( $a, $b ){ $aPor = (int) get_post_meta( $a, 'photo_order', true ); $bPor = (int) get_post_meta( $b, 'photo_order', true ); if (

python学习值字典和集合

房东的猫 提交于 2019-12-24 16:49:03
集合定义总结 创建一个空集合必须用 set() 而不是 { }.{ } 是用来创建一个空字典。 集合里面的元素必须是不可变的数据类型。 通过set方法可以将列表/元组/字符串转换成集合数据类型。 >>> s1 = {} >>> type(s1) <class 'dict'> >>> s2 = {1, 2, 3} >>> type(s2) <class 'set'> >>> s3 = {1, 3.14, True, 'hello', [1, 2, 3], (1, 2, 3)} Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'list' >>> s3 = {1, 3.14, True, 'hello',(1, 2, 3)} >>> type(s3) <class 'set'> >>> s4 = set([]) >>> type(s4) <class 'set'> >>> s5 = set('abcde') >>> s5 {'c', 'e', 'b', 'a', 'd'} >>> type(s5) <class 'set'> 集合(set)是一个无序的不重复元素序列。1,2,3,4,1,2,3 = 1,2,3,4 集合的创建: 1).

iPhone - Changing a sub-sub-sub NSMutableDictionary value

我的梦境 提交于 2019-12-24 13:22:40
问题 If I have a data tree that is something like : NSMutableDictionary (dict1) NSMutableDictionary (dict2) NSMutableArray (array) NSMutableDictionary (dict3) Key1 Key2 NSMutableDictionary (dict_n) Keyn Keyn NSMutableDictionary (dict_n) NSMutableArray (array_n) NSMutableDictionary (dict_n) Keyn Keyn NSMutableDictionary (dict_n) Keyn Keyn If I want to change the value of Key1, is there a simplier way than... getting dict1 then getting dict2 then getting array then getting dict3 converting dict3 to

Iterate over list to get value by its name

二次信任 提交于 2019-12-24 10:59:43
问题 This works. But are there more efficient/simpler ways to get output ? test_list <- list(list("name"="A","property"=1), list("name"="B","property"=2), list("name"="C","property"=3)) myFunction <- function(arg1=NULL, arg2=NULL){ arg1[[arg2]] } # works output <- sapply(test_list, myFunction, "property") # returns NULL # output <- sapply(test_list, `$`, "property") 回答1: We can specify the anonymous function call to do the extraction sapply(test_list, function(x) x$property) #[1] 1 2 3 来源: https:/

Why does parsing a blank line with Spirit produce an empty key value pair in map?

橙三吉。 提交于 2019-12-24 10:27:55
问题 I'm trying to use Spirit.Qi to parse a simple file format that has key value pairs separated with an equals sign. The file also supports comments and blank lines, as well as quoted values. I can get nearly all of this to work as expected, however, any blank lines or comments cause an empty key value pair to be added to the map. When the map is traded for a vector, no blank entries are produced. Example Program: #include <fstream> #include <iostream> #include <string> #include <map> #include

Replace String with Value of Dictionary

偶尔善良 提交于 2019-12-24 07:17:27
问题 I will simplify as much as possible. I have a DataFrame with a list of businesses by state. Some States are abbreviated, some are not. I want to replace the full state name with the Abbreviation (ex: New Jersey to NJ). I found a cool module "US" found here that lists all the states and their abbreviations in a dictionary. What I would like to do is replace the full name with the abbreviations. code: import pandas as pd import numpy as np import us dfp = pd.DataFrame({'A' : [np.NaN,np.NaN,3,4

How to sum values in dictionary based on position?

删除回忆录丶 提交于 2019-12-24 05:52:40
问题 I have a dictionary that for each key there are five values in list, such as: {"A": [0, 0.12, 0, 0.73, 0], "B": [0.96, 0, 0.30, 0, 0], "C": [0, 0, 0, 0.11, 0], "D": [0, 0.07, 0, 0.42, 0]} I want to sum first, second and etc. values for all keys and add it in new list such as: [0.96, 0.19, 0.3, 1.26, 0] I tried by below code solve it but It didn't work: aa = {"A": [0, 0.12, 0, 0.73, 0], "B": [0.96, 0, 0.30, 0, 0], "C": [0, 0, 0, 0.11, 0], "D": [0, 0.07, 0, 0.42, 0]} bb = [] for value in (aa

php compare array keys, not values

萝らか妹 提交于 2019-12-24 01:18:50
问题 I am successfully using the array_key_exists(), as described by php.net Example: <?php $search_array = array('first' => 1, 'second' => 4); if (array_key_exists('first', $search_array)) { echo "The 'first' element is in the array"; } ?> But, take out the values, and it doesn't work. <?php $search_array = array('first', 'second'); if (array_key_exists('first', $search_array)) { echo "The 'first' element is in the array"; } ?> Not sure how to only compare 2 arrays by their keys only. 回答1: The

Filling a series based on key value pairs

主宰稳场 提交于 2019-12-23 22:12:43
问题 I have a data frame that includes a dictionary of codes and names. Some of the names are blank. I'm trying to fill those blanks based on other examples where the code matches a name. Thus far I have sorted into a df by code but can't figure out how to "fill in the blanks". Here is my code: import pandas as pd import json from pandas.io.json import json_normalize df = pd.read_json('data/world_bank_projects.json') theme= pd.DataFrame([val for pair in df['mjtheme_namecode'].values for val in

Plotting Deedle frame

谁说我不能喝 提交于 2019-12-23 20:14:50
问题 I have the following piece of code: let mychart = frame.GetAllSeries() |> Seq.iter(fun key value -> Chart.Line(value, Name=key) |> Chart.Combine where frame.GetAllSeries() returns a seq<KeyValuePair> . I'd like to pipe the sequence directly in a chart. I thought I could iterate through the sequence. The problem is that I can't find an idomatic way to access the key and value separately that could be plugged in directly in the lambda expression. Thanks. EDIT This works: let chart = frame