How to apply Python generators to finding min and max values?

I’m solving yet another problem in HackerRank (https://www.hackerrank.com/challenges/determining-dna-health/problem). In short: you are given 2 arrays (genes and health), one of which have a ‘gene’ name, and the other – ‘gene’ weight (aka health). You then given a bunch of strings, each containing values m and n, which denote the start and end of the slice to be applied to the genes and health arrays, and the ‘gene’-string, for which we need to determine healthiness. Then we need to return health-values for the most and the least healthy strings.

My solution is below, and it works, but it’s not scalable, i.e. it fails testcases with a lot of values.

import re
if __name__ == '__main__':
    n = int(input())

    genes = input().rstrip().split()

    health = list(map(int, input().rstrip().split()))

    s = int(input())
    weights = ()
    for s_itr in range(s):
        m,n,gn = input().split()
        weight = 0
        for i in range(int(m),int(n)+1):
            if genes(i) in gn:
                compilt = "r'(?=("+genes(i)+"))'"
                matches = len(re.findall(eval(compilt), gn))
                weight += health(i)*matches
        weights.append(weight)
    print(min(weights), max(weights))

Can you advise on how to apply generators here? I suspect that the solution fails because of the very big list that’s being assembled. Is there a way to get min and max values here without collecting them all?

Example values:

genes = ('a', 'b', 'c', 'aa', 'd', 'b')
health = (1, 2, 3, 4, 5, 6)
gene1 = "1 5 caaab" (result = 19 = max)
gene2 = "0 4 xyz" (result = 0 = min)
gene3 = "2 4 bcdybc" (result = 11)

This case returns 0 19

views – How do I apply HTML IDs to field output result?

I’m trying to build a block for tb_megamenu of a view of items of a certain content type. I want to use some JavaScript so that when the end user hovers over a title then associated content appears on the right hand side.

I’ve got the JavaScript/jQuery functionality working by attaching a library to the views display twig template and it works with a simple global text field using the correct IDs. However, it won’t work with tokens because all ids will apply to all instances of the field content, so that hovering will show all related content.

Is there a way to separate the fields out like a delta field? I can build this in HTML ultimately but it wont be manageable buy the end user ultimately.

python – Apply additions on a base array based on date ranges

please roast my code, I hope this is the good place to look for some advice on where I can improve.

Problem definition:

Apply modifications on values depending on date ranges.

Data:

Base array – holds dictionaries in the following format:

({‘date’: 20200101, ‘value’: 1}, {‘date’: 20200102, ‘value’: 2})

Modifier array – holds dictionaries with similar format:

({‘date’: 20200101, ‘value’: 1}, {‘date’: 20200201, ‘value’: 2})

Goal:
Add the respective value of the modifier array to the base array lining up the date ranges. Dates are exclusive, for example when the modifier array contains 2020-01-01 you have to add the value ‘1’ to all values in the base array that have a date less than 2020-01-01. Base array has a lot of elements while modifier array relatively few. In practice this splits the base array into a couple of date ranges. If the last modification date is less than the date in base array no modification is required.

My solution:

This is assuming the comparing of dates will work, I have translated this from perl for an easier read.

mod_index = 0 
mod_size = len(mod_arr)

for elem in base_arr:
  if elem('date') > mod_arr(mod_size - 1)('date'):
    break
  else:
    if elem('date') < mod_arr(mod_index)('date'):
      elem('value') += mod_arr(mod_index)('value')
    else:
      elem('value') += mod_arr(mod_index + 1)('value')
      mod_index += 1

magento2 – Apply filters or mass actions on grids with fake collection (or wirhout ui components)

I a admin grid with a change on _prepareCollection() function to get the collection from a response of api call, its working fine. But I do not have the filters or mass functions, how can I do that without ui components?

enter image description here

I have this change on my grid file:

/**
 * Collection
 *
 */
protected function _prepareCollection()
{
    $filter = (
        'query' => 'cat yellow',
        'page' => 1,
        'region' => '',
        'year' => '',
    );

    $collection = $this->_api->searchCat($filter);

    $this->setCollection($collection);
    return parent::_prepareCollection();
}

If I could simulate a collection, maybe I could use ui components, but I’m lost, how can I resolve my problem?

The idea is use the filter to search cats with cat api, and the mass action is to import those registers into a products.

How to force Slack to apply markdown within a word?

Slack has “recently” introduced its a bit annoying WYSIWYG “message composer” which breaks the message formatting with the inline markdown. Fortunately there is now also option called “format messages with markup” which kind of reverts this feature back to normal, but…

I would like to know, how to force this inline markdown interpreter to work also in the middle of words. For example, how to achieve these:

partiallystrike

connected

Apparently, the following:

par~tiallys~trike

`connect`ed

do not work. There must be a separator before/after ~ or `, but if space is used, it’s no more a single word 🙁 Is there any “invisible” (and simply reachable) character Slack would accept as a separator which we could use for this purpose?

How to take values from a file, apply an equation to those values, and write them to file in c

How do I take values from a file, apply an equation to those values, and write them to file in c
It seems simple, what I’ve tried just writes the same number as many times as I have samples. I would like to write a file with the new values.

   printf("Enter the number of sample values in the file minus 1.n");  //11025
   scanf("%d",&n);

   printf("using %d sample values.n",n);

    //  fseek(filein, "%lg", SEEK_SET);
   for ( c = 0 ; c <= n ; c++ )//     // Convert a reading (which goes from 0 - 65536) to a value (-1 - 1):
                                      // float voltage = sensor * (1 / 65536.0);
   {
      fseek(filein, n, SEEK_SET);
      fscanf(filein, "%lg", var);

      sum = var * (maxy / 65536.0);
//todo?

//todo?
   fprintf(fileout,"%lgn",sum);
   }
   getchar();
fclose(filein);
fclose(fileout);
   return 0;
}



return 0;
} ```

germany – Do I qualify for a German visa? How do I apply?

In the website of Germany Embassy in U.K., it is stated that

(…)

Urgent reasons for entry exist especially in the following cases.

(…)

4. Educational reasons

initial entry: documentation from the apprenticeship or study
institution regarding the requirement of in person attendance as well
as proof of accommodation.

(…)

Similarly, the interior minister of Germany government states that

What are valid grounds for crossing the border?

(…)

Travellers can be permitted to cross borders to visit their partners
or families, receive medical treatment, attend educational and
training institutions that require in-person attendance, or attend
important family events.

My situation as follows, I will conduct internship starting from 15 of June, and I am starting to my Master’s program on the 1st of September of this year, both in Germany.

However, I am a Turkish national, living in U.K. for the last 6 months.

Now, I have to get a visa in order to enter Germany, but neither the embassy haven’t, nor visametric (the external source which handles the visas for German embassy) opened, yet.

To make sure that I understand everything correctly: Am I allowed to get a German visa?

If so, how do I supposed to get it since visametric is closed?

germany – Am I entitled to apply for a German visa

In the website of Germany Embassy in U.K., it is stated that

(…)

Urgent reasons for entry exist especially in the following cases.

(…)

4. Educational reasons

initial entry: documentation from the apprenticeship or study
institution regarding the requirement of in person attendance as well
as proof of accommodation.

(…)

Similarly, the interior minister of Germany government states that

What are valid grounds for crossing the border?

(…)

Travellers can be permitted to cross borders to visit their partners
or families, receive medical treatment, attend educational and
training institutions that require in-person attendance, or attend
important family events.

My situation as follows, I will conduct internship starting from 15 of June, and I am starting to my Master’s program on the 1st of September of this year, both in Germany.

However, I am a Turkish national, living in U.K. for the last 6 months.

Now, I have to get a visa in order to enter Germany, but neither the embassy haven’t, nor visametric (the external source which handles the visas for German embassy) opened, yet.

To make sure that I understand everything correctly: Am I entitled to get a German visa?

If so, how do I supposed to get it since visametric is closed?

dnd 5e – Do class or subclass features that relate to spellcasting apply when producing a spell’s effect from an Artificer’s Spell-Storing Item?

In my recent question about a homebrewed Artificer subclass, I was asked in a comment how one of the abilities that modifies spellcasting would interact with casting spells stored within a my subclass’s variant version of the Spell-Storing Item feature that all Artificers get. I’d not considered it before, but I suspect it should work the same as a normal spell cast from a normal Spell-Storing Item.

But as it turns out, I’m not actually sure how that works for normal Artificers either. The relevant rules text for the Spell-Storing Item feature says (from Eberron: Rising from the Last War, page 58, and the latest version of Wayfinder’s Guide to Eberron, p. 179-180) says:

While holding the object, a creature can take an action to produce the spell’s effect from it, using your spellcasting ability modifier. If the spell requires concentration, the creature must concentrate.

Notable in that rules text is that it does not say that the creature using the object casts the spell, only that it produces the spell’s effect. This seems relevant because the top voted answers to this previous question seem to mostly attach to the “cast” terminology used by most magical items that grant extra spells.

In combination with the answers to that question, it seems like the different language (not using “cast”) may mean that using a Spell-Storing Item isn’t spellcasting, and so no feature that modifies spellcasting will apply. But there’s enough ambiguity that I want to ask about it here.

Do an artificer’s spellcasting-related features apply to spells they store in an item? Do spellcasting-related features of the creature using the Spell-Storing Item (which may or may not be the Artificer themself) apply?

For a concrete example, if an Artillerist stores Scorching Ray in a wand, staff or rod that they had previously made their Arcane Firearm, would they get an get an extra d8 to add to one of the spell’s damage rolls when they use the stored spell?

dnd 5e – Does the creature trait Angelic Weapons apply to any weapon used by the creature?

The planetar does a massive amount of damage for a CR16 creature. I was wondering, if you gave it an adamantine greatsword (which deals critical hits to objects), what would happen if it struck an object?

My worry is whether or not the Angelic Weapons bonus applies only to some magical divine sword carried by the planetar, or if it’s applied to any weapons used by the angel.

Normally it does 4d6+5d8+7 per single attack (not counting multi—attack). With an adamantine greatsword (which I’m guessing I can’t say it’s conjured with), would it do 8d6+10d8+7 damage to the object?

I want to use this for a wizard, who would Shapechange into a planetar, equip an adamantine greatsword, then attack some boats (by Ghosts of Saltmarsh standards, it could destroy most boats in two turns).

Here is the description for the ability:

Angelic Weapons: The planetar’s weapon attacks are magical. When the planetar hits with any weapon, the weapon deals an extra 5d8 radiant damage (included in the attack).