Associations complement

So I'd like to complement two associations through shared keys... not the best description, so here's an example:

a = <|"a" -> 1, "b" -> 2, "c" -> 3|> b = <|"a" -> 1, "b" -> 5|> 

The questions is, how b differs from a with respect to common keys only, so c doesn't matter.

And by differs I mean, what minimal example of x fulfills:

<|a, x|> ===  <|a, b|> 


I could go with:

Complement @@ [email protected]{b, a} // Association 
<|"b"->5|> 

but stripping associations seems wrong to me. Is there more generic approach?

p.s. in general case one may want to get inf about missing keys too, then:

 Complement @@ Normal @ KeyUnion[{b, a}] 
{"b" -> 5, "c" -> Missing["KeyAbsent", "c"]}  

Replay

Complement seems to work without stripping Association in both cases.

Complement[b, a]
(* <|"b" -> 5|> *)

Complement[Sequence @@ KeyUnion[{b, a}]]
(* <|"b" -> 5, "c" -> Missing["KeyAbsent", "c"]|> *)

What version are you using?

Category: functions Time: 2016-07-30 Views: 10

Related post

  • How to iterate through a list of rules? 2015-03-26

    Let's consider I have a list of rules: {Aa -> 1/2, Av -> 2/5, Bx -> 3/7, Ce -> 4/9, ...} I want to find all keys that contain the letter "A" and change their values to expressions. This means to have as a result: ***Some code here...

  • Association without an associated value 2014-12-28

    Sometimes, we only need to store the keys which will be checked whether certain keys exist in the data structure(corresponding data structures in C++ are std::set or std::unordered_set). Despite the presence of the old posts such as Implementing a di

  • Change value associated with keys using alternatives 2015-06-19

    I have a List of Associations that contains a Key called "ClaimBasis". There are about 10 possible values that ClaimBasis can take on, one of them being the value Null. I want all values that are equal to "Risks Attaching" to be change

  • Is there an idiomatic way to determine whether an `Association` is a subset of another? 2015-07-20

    I would like a way to tell if every key-value pair of an Association is contained in another. For instance, f[<|c -> 1, d -> 2|>, <|a -> 1|>] should evaluate False, but f[<|a -> 1, d -> 2|>, <|a -> 1|>] should eva

  • Finding associations not having value Missing["Unmatched"] in a list of associations 2015-10-15

    I have a list of Associations, a: {<|"Year" -> 2011, "Loss" -> 141972., "Factor" -> 1.02884|>, <|"Year" -> 2009, "Loss" -> 27081., "Factor" -> 1.01863|>, <|"

  • Efficient way to compute a complement while respecting multiplicities 2016-06-25

    Suppose I have list2 which is a subset of list1. I want to get a res by deleting an element from list1 whenever there is such an element in list2. I think of this as being the reversal of the operations of Join and Complement which respects multiplic

  • Using AR::Associations to limit find() scope 2006-07-02

    In an ecommerce application I'm currently building there's a URL for destroying a line item in the user's cart: http://127.0.0.1:3000/cart/line-item/16/destroy Like all good web coding monkeys should, I'm going to need to check that the LineItem with

  • How do I destroy or reset a file association in Windows Vista? 2009-05-19

    I inadvertantly got .py files stuck to opening my editor instead of running. --------------Solutions------------- The reset part is detailed in this article: Click Start Menu, and then type regedit in the Start Search and press ENTER. Navigate to the

  • Obtain port names & associated IP addresses on W2K Print Server 2009-06-03

    I hope someone can help, my brain is fried! In W2K3, I can use prnmngr.vbs and get absolutely everything I need from the print server to list installed queues, port names, driver details, IP addresses etc. But on Server 2000, the script doesn't work

  • Precedence & Associativity in C 2009-06-04

    int main(int argc, char ** argv) { int i = 0; i = i++ + ++i; printf("%d\n", i); // 3 i = 1; i = (i++); printf("%d\n", i); // 2 Should be 1, no ? volatile int u = 0; u = u++ + ++u; printf("%d\n", u); // 1 u = 1; u = (u++); pri

  • Get first key in a (possibly) associative array? 2009-06-22

    What's the best way to determine the first key in a possibly associative array? My first thought it to just foreach the array and then immediately breaking it, like this: foreach ($an_array as $key => $val) break; Thus having $key contain the first k

  • Can file extensions be associated with TS2008 Remote Applications 2009-06-30

    Just wondering if there's any way to associate a local file extension with a remote app running via a Windows 2008 Terminal Services session? If, for example, I've published Acrobat as a Remote App, is there any way of making it launch when I double-

  • How do I stop QuickTime from repeatedly stealing file associations? 2009-07-16

    Every time I update Quicktime on both Vista and XP, I lose file associations I made for VLC (my preferred player). I only keep QT around for the odd browser video, and would prefer to keep it without it surprising me every couple months by stealing f

  • File association for editing on a mac 2009-08-03

    I'm quite experienced with how file association works for opening files on Mac OS X. I recall reading somewhere that OS X keeps not only the information about which apps can open a file, but also which apps can edit a specific file type. I'm having p

  • Finding the machine associated with an ip 2009-08-13

    Is it possible to find out if a public ip is associated with a router or a pc? At my home i have internet connected to my pc through a netgear router. The router is connected to the internet modem. When i try to login to isp website through my router

  • What program do you use to edit file associations in Vista and Windows 7? 2009-08-14

    We all know that Vista and Windows 7 doesn't let you specify custom extensions or customize them to your liking. What program do you use to edit file associations in Vista and Windows 7? EDIT: Just to be more clear, I'm looking for a program which le

  • My .txt file association is missing its icon 2009-08-22

    On Windows XP, my .txt file association has no icon. It is quite annoying, and has been going on for several months now. I've tried to un-associate it using the folder-->options--file types, I've tried to change the association, delete the icon cache

  • Changing program associations 2009-08-25

    We currently have two versions of an application (CS3 and CS4) on our XP build. It defaults to the wrong version (CS4) when opening documents. What registry changes do we need to make to change the defaults? (Or a similar scriptable fix)? Thanks ----

  • File Association Dilemma in Vista 2009-08-27

    I have both Office 2003 and Office 2007 installed on my laptop. I need Office 2007 occasionally for work-related issues but for all other purposes I use Office 2003. But now when I double-click on a .doc or .xls file it gets opened with the correspon

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.761 (s). 13 q(s)