how to merge two lists based on common key value in python

I am trying to get some data from remote server based on fields provided in HTTP/POST request. There are some 1500 fields, however at any given time I can query only 30 fields. So I am breaking the 1500 fields in 50 chucks and making 50 requests to remote host. Return data contains 5000 json records for each 30 fields. I want to merge results from all 50 requests and load final data in MongoDB. I developed following code, is there a better or efficient solution?

import requests
import json
import time 
current_time = datetime.datetime.utcnow()

#certain code ommited 
main_data_list=()
i=0
n=30
# there are about 1500 data fields, separated by 30 chuncks
for r in data_field_chuncks:
    rr = '"name" , '+', '.join('"{0}"'.format(w) for w in r)
    ##print (rr)       
    query_data = rr
    keys = json.loads(query_data)
    response = requests.post('remote_host', headers=headers, data=query_data)
    response_data = json.loads(response.text)
    
    
    for r in response_data('data'):
        # there are about 5000 different names
       
        fieldvalues = (r('d')(0:len(keys('columns'))))
        json_lines = {}
        for n, v in zip(keys('columns'), fieldvalues):
            json_lines(n.replace(".","_").replace("|","__").replace("(","_").replace(")","_")) = v   
        if i==0:
            json_lines("t") = current_time
            #print (json_lines)
            main_data_list.append(json_lines)            
        else:
            for sub_list in main_data_list:
                #each time there will be 5000 look ups
                if sub_list('name')==json_lines('name'):
                    sub_list.update(json_lines)
            
    i=i+1
    time.sleep(1)

for line in main_data_list:
    mongo_database.insert_one(line)

At least 3 apps have odd behaviors recently in 20.04 LTS – is there a common cause?

LibreOffice ‘send by email’ has suddenly started giving an encoded filename to my email client (Claws)
Acroread is now unable to print more than the first page of a multi-page selection
SimpleScan (Document Scanner) sees the ADF, but when that is selected, scans from the glass anyway

Has some recent system update altered the way the instruction strings are being treated?

In Microsoft Excel, is it possible to automatically obtain the sum of the cells which have a common merged cell next to them?

Manual additions for illustration purposes

I am looking for a formula that would give me —

  • in cell C1, the sum of B1 and B2, as the two cells have the merged cell A1 next to them;
  • in cell C3, the sum of B3, B4 and B5, as the three cells have the merged cell A3 next to them;
  • in cell C6, the sum of B6, B7, B8, B9, as the four cells have the merged cell A6 next to them, and so on.

Is there any such formula?

powerapp – How can I insert selected Listbox items as a new record in to a common data service table

I have a PowerApps canvas App and I have a requirement of creating new records for all selected listbox items in to a table. I am acually trying to implement a many to many relationship scenario

my Listbox name is: ListBox1 and my table name is ContactsTable inside the page I have put a button and on click of button I put the following PowerApps logic:

  ForAll(ListBox1.SelectedItems,Patch(ContactsTable ,Defaults(ContactsTable),{EmpID:2,Name:ListBox1.Selected.Name}));

it creates the last selected item repeated based on the number of items i select from listbox any Idea would be great.

architecture – What is the most common approach for microservices to access data managed by other micro services?

I am exploring using a microservice architecture. Among others, this would include three services, an Orders Service, a Products Service, and a Fulfillment Service.

Let’s say the Fulfillment Service needs information about an order. What would be the more common and most accepted method for Fulfillment Service to access the order information?

  1. Fulfillment Service requests order data directly from Order Service via HTTP.

  2. Both Fulfillment Service and Order Service track copies of order data in their own databases. When orders are created, updated, or canceled, a message would be published which both services would listen for and handle.

    1. This might result in higher fault tolerance: if Order Service goes down, the Fulfillment Service can continue operating independently via its own copy of data.
    2. I suppose with this approach, you’d want to avoid allowing Fulfillment Service to modify product (each microservice would be the source of truth for its particular data).
  3. Another approach.

architecture – Common base class of multiply inheriting classes

I’m using a 3rd party library with the following class hierarchy:

class A {};
class B {};
class C1 : public A, public B {};
class C2 : public A, public B {};

What would be a type that accepts instances of C1 and C2, giving access to all their public members inherited from A and B?

class D : public A, public B {}; does not work because the compiler doesn’t know how to convert from C1 or C2 to D.

android – SQLite – get every row that has a common entry in the second column

I am working on a Android studios project and i have a table that has two columns item and listname.

enter image description here

i want to get all the items that have a commun Listname so in this case if i were looking for items that have Market as a Listname i only want to get the last 4 from the table, i only want to return the items. i have this but it keeps crashing.

   public Cursor getItem(String listname) {
    SQLiteDatabase db = this.getWritableDatabase();

    String selectQuery = "SELECT  * FROM " + LIST_ITEM_TABLE + " WHERE "
            + ItemListName + " = " + listname;

    Cursor c = db.rawQuery(selectQuery, null);
    
    return c;
}

python – Lowest Common Ancestor in Binary Tree (Iterative)

In the below code I’ve implemented a method to find the lowest common ancestor of a binary tree.

This is an iterative approach using this pseudocode.

Please suggest any improvements that can be made.

class Node:
    def __init__(self, data=None, left=None, right=None):
        self.data  = data
        self.left  = left
        self.right = right

def lowest_common_ancestor(root, node1, node2):
    parent = {root: None}
    stack = (root)

    while node1 not in parent or node2 not in parent:
        node = stack(-1)
        stack.pop()
        if node.left:
            parent(node.left) = node
            stack.append(node.left)
        if node.right:
            parent(node.right) = node
            stack.append(node.right)

    ancestors = set()
    while node1:
        ancestors.add(node1)
        node1 = parent(node1)
    while node2 not in ancestors:
        node2 = parent(node2)

    return node2.data

def main():
    '''
    Construct the below binary tree:

            30
           /  
          /    
         /      
        11      29
       /      /  
      8   12  25  14

    '''
    root = Node(30)
    root.left  = Node(11)
    root.right = Node(29)
    root.left.left  = Node(8)
    root.left.right = Node(12)
    root.right.left  = Node(25)
    root.right.right = Node(14)

    print(lowest_common_ancestor(root, root.left.left, root.left.right))       # 11
    print(lowest_common_ancestor(root, root.left.left, root.left))             # 11
    print(lowest_common_ancestor(root, root.left.left, root.right.right))      # 30


if __name__ == '__main__':
    main()

c# – Endpoint to process multiple json object formats then map to common format

I’m creating an api endpoint which is intended to receive data from multiple clients.

Each client may or may not have their own json object structures, and may change their structures over time.

I want to create a mapper which maps json objects from an expected structure (based on the client ID) to a persistent structure.

The idea is to:

  1. Accept the input and compare to the specific client’s format (Use Json Schema for validation)
  2. Deserialize json into object of type json schema
  3. Map object to persistent structure type. (Not sure what to use here/just build it myself)

So both the Json Schema and the mapper would need to be updateable at runtime, in order to accomodate format changes to data from clients.

This whole endeavor is intended to remove the need to redeploy the application if a new client is added or an existing client changes their json format.

Is there a simpler approach to this problem, or a tool that would simplify the mapping from one json object structure to another?

plotting – How can I get rid of common areas in this plot?

I want to realize the domains in which $sin x<0$ and $sin x geq 0$. I use this code

Plot[{Sin[x], If[Sin[x] < 0, 0], If[Sin[x] >= 0, 0]}, {x, 0, 10}, 
 PlotStyle -> {Automatic, 
   Directive[Yellow, Opacity[60], Thickness[.08]], 
   Directive[Red, Opacity[1], Thickness[.03]]}]

and I get
enter image description here

In the plot, the yellow and red parts have some common areas which are not true! How can I modify it to have the exact result? I have to use a big thickness for them since I want them to be visible over a large number of $x$.