python 3.x – grouping the list of key values into the list of dictionary

I have a List of dictionaries that have Names and country and other info, like so:  

mylist  = [ {'key': 'captial' , 'value': 'captial of india'},
            {'key': 'captial' , 'value': 'captial of usa'},
            {'key': 'fruit' , 'value': 'colour of apple'},
            {'key': 'fruit' , 'value': 'colour of orange'}]

So here to group the keys and format the value of that particular key

result=[{'title':'captial',questions:[{text:'captial of usa'},{text:'captial of india'}]},
        {'title':'fruit',questions:[{text:'colour of apple'},{text:'colour of orange'}]}]

rest – Grouping the APIs based on the resources or access levels (public, authorized)?

We are designing our APIs and are struggling to come up with how to group them

We have following types of resources

  1. Public (access from any domain)
  2. Public but with CORS
  3. Authenticated with role based
  4. API key and secret access

We are planning to write them as middlewares (CORS middleware, Auth middleware, Admin middleware)

Coming to our question

Should we design our API as

  1. /public
  2. /authorized
  3. /authorized/admin
  4. /daemon/

this allows us to group better but it could be messy as many user related APIs could get split into /authorized and /authroized/admin

Second approach we can follow is to use /users and then apply middleware to each group separately but with this approach we fear that someone might forget to add a middleware where it should be whereas with first approach you just need to know what kind of access you need to provide and you are good to go. The second approach looks cleaner but leaves a window for error open which we can keep closed by being careful but still we would like to learn from the community.

graphs – Clustering algorithm for grouping polygons with the same sides into clusters

Given a number of specific type polygons (i.e., each polygon has the same number of sides but the shape could be different), is there any clustering algorithm that can be used to group all of them into clusters?

For example, given 50 hexagons with different shapes, I want to group all of them into 4 clusters according to their similarity.

sql server – Grouping by Semantics

I am trying to find ways to group articles based on their semantics, and probably only target the articles’ title. For example, in a table I have news articles for multiple subjects, I want to get the top 10 articles grouped by subject.

Azure cognitive search provides semantic search, but a search keyword needs to be provided. In my case, I want to list all existing different article subjects, which means the engine should already know about their interrelation.

If I have eight articles related to police violence and two about defrosting chicken, then two articles should be returned.

Could anyone guide me through this? Does it even exist?

SharePoint Online Highlighted Content Query Text Grouping

Stack Exchange Network

Stack Exchange network consists of 177 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Grouping results and combining duplicates as array

I’m trying to write a query that gets all the records grouped by code and the rows that are duplicated are aggregated into an array.

| code     | name    |
| a        | Mike    |
| b        | Jones   |
| b        | Who     |

expected result:

| code     | name           |
| a        | Mike           |
| b        | [Jones, Who]   |

list – SharePoint Template Grouping Using Handlebars

I have a SharePoint Online list that includes a title, URL, and a category. My category options are “Forms” and “Tools”.

I want a HandleBars template that will loop through this list and group by category.

My Code:

{{#each items}}
<li> <a href="{{URL.textValue}}">{{Category.textValue}} - {{Title.textValue}}</a> </li>

Here is what I get for results:

Forms & Tools

  • Forms – Employee Form
  • Forms – Customer Form
  • Tools – Order Sets
  • Tools – Self Service
  • Tools – Time Tracking

What I want to get is this:


  • Employee Form
  • Customer Form


  • Order Sets
  • Self Service
  • Time Tracking

I have tried doing a loop inside of a loop using {{#each items}}, but could not get this to work.

How can I do the looping so that it goes through my list and identifies the Categories, and groups the URL/Titles underneath each category?

sharepoint foundation – Add color to specifc list cells after grouping

Faced a simple task. But I can’t find a solution.
There is a regular list with 6 columns. But the list has been grouped according to one of the fields. (it is assumed that the list will be updated and you need to structure it somehow).
enter image description here
There is code that works on this list without grouping the elements.

OnPostRender: function(ctx) {
        var statusColors =  {
  'W' : '#fc6a6a',  
  'R' : '#FFD800',
  'Y' : '#01DF3A' 

   var rows = ctx.ListData.Row;
   for (var i=0;i<rows.length;i++)
         var status = rows(i)("flag");
         var rowId = GenerateIIDForListItem(ctx, rows(i));
         var row = document.getElementById(rowId);  = statusColors(status);

But it does not work when you enable grouping.

as I vizhk to the moment of expansion of group, the data is not loaded yet.
Which direction to look ??
I tried to use the CSR, but then an error immediately appears. I can’t do anything with her.

I tried solutions where they change the color of the lines. But it does not work in my case

string manipulation – Grouping list elements according to a condition

I have a list of “calls and responses”, which are pairs of a message and then either a $0$, for a call, or a $1$, for a response. There is some amount of calls, and some amount, potentially unequal, of responses in answer. An example of such a list might be the following:

{"Call 2",0},
{"Call 3",0},
{"Response 2",1}}

The text is arbitrary, and won’t actually contain “call” or “response”. What I am trying to do is group this list into an association of calls to responses, so that the list above would become

{{"Call","Call 2"}->{"Response"},
{"Call  3"}->{"Response","Response 2"}}

I looked at GroupBy and GatherBy but they seem to re-order the list, which I don’t want to do. The order should stay the same, just with calls and responses sorted together. How can I achieve this elegantly?

Bonus points if the answer can also cut out extraneous responses with no calls at the beginning of the list, and extraneous calls with no response at the end of the list.

Grouping / Categorizing Enums in C++

  1. each enum should have a group / categorization
  2. dont have to manually write enum indexes and ranges for the groups
  3. in one class so i can easily use as variables

my current approach is to encode the group index in the last few bits of the enum integer value:

#define TokenizerState_Normal 0
#define TokenizerState_InComment 1
#define TokenizerState_InLiteral 2

enum class TokenizerState : uint_fast32_t {

#define State (__COUNTER__ | ((GROUP << 25))) //Encode group into last 7 bits (of 32)

#define GROUP TokenizerState_Normal
#undef GROUP

#define GROUP TokenizerState_InComment
    InComment = State,
    InCommentMultiline = State,
#undef GROUP

#define GROUP TokenizerState_InLiteral
    InStringQuote = State,
    InStringDoubleQuote = State,
    InStringBacktick = State,
    InInteger = State,
    InDecimal = State,
    InIdentifier = State
#undef GROUP

#undef State


//Get what group an enum belongs to. Returns 0,1 or 2 (groups defined above)
#define GetTokenizerStateGroup(INDEX) ((((unsigned int)INDEX) & 0xFE000000) >> 25)

but id like to make it a bit more readable and avoid macros if possible. i need to be able to get what group a TokenizerState enum is in. currently i do that by checking those last bits in the GetTokenizerStateGroup macro.

i do it this way because i actually have many enums and its a lot faster and easier to compare against a category than each enum (and since all intrinsically hold a group i dont have to do a lookup or comparison from a list). and since i have many and edit often, i dont want to write indexes and group ranges each time i edit.

im not that advanced in c++ so templates and other more modern c++ constructs are all welcome, as long as it mostly satisfies the conditions.