python – Structural Pattern Matching syntax to match a value in a list

I was looking into Python 3.10’s Structural Pattern Matching syntax, and I want to refactor one of my code that uses if-else, using structural pattern matching. My code works, but I’m trying to find out if there’s a better way to deal with a particular section.

Let’s consider this simple example problem, let’s say I have the following list:

data = (                    # index
    (1, 2, 5, 3, 4),        #   0
    (7, 5, 8, 4, 9),        #   1
    (2, 3, 4, 4, 5),        #   2
    (1, 3, 1, 6, 7),        #   3
    (5, 6, 0, 7, 8),        #   4
    (4, 3, 0, 7, 5),        #   5
    (4, 4, 4, 5, 4),        #   6
    (5, 2, 9, 3, 5),        #   7
)

What I want to do is:

IF: (there is a `4` *or* `5` at the *beginning*)
    prepend an `'l'`.

ELIF: (there is a `4` *or* `5` at the *end*)
    prepend a `'r'`.

ELIF: (there is a `4` *or* `5` at *both ends* of the list)
    IF:  (Both are equal)
        prepend a `'b2'`, 
    ELSE: 
        prepend `'b1'`

ELSE:
    IF : (There are at least **two** occurrences of `4` *and/or* `5`) 
        prepend `'t'`
    ELSE: 
        prepend `'x'`

Each inner_list may contain arbitrary amount of elements.

###Expected Result:

index   append_left
  0         'r'
  1         't'
  2         'r'
  3         'x'
  4         'l'
  5         'b1'
  6         'b2'
  7         'b2'

Now, I can do this using structural pattern matching, with the following code:

for i, inner_list in enumerate(data):
    match inner_list:

        case ((4 | 5) as left, *middle, (4 | 5) as right):
            data(i).insert(0, ('b1', 'b2')(left == right))

        case ((4 | 5), *rest):
            data(i).insert(0, 'l')

        case (*rest, (4 | 5)):
            data(i).insert(0, 'r')

        case (_, *middle, _) if (middle.count(4) + middle.count(5)) >= 2:  ## This part ##
            data(i).insert(0, 't')
        
        case _:
            data(i).insert(0, 'x')

pprint(data)

Output:

(('r', 1, 2, 5, 3, 4),
 ('t', 7, 5, 8, 4, 9),
 ('r', 2, 3, 4, 4, 5),
 ('x', 1, 3, 1, 6, 7),
 ('l', 5, 6, 0, 7, 8),
 ('b1', 4, 3, 0, 7, 5),
 ('b2', 4, 4, 4, 5, 4),
 ('b2', 5, 2, 9, 3, 5))

The problem is the ## marked block above. Of course I can move that part inside the block, and check there, but I was wondering whether the if part can be avoided altogether, i.e. some pattern that would match at least two 4 and/or 5s.

sharepoint online – Gulp serve “Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.”

I want to build a SharePoint web-part, so i run these commands:-

yo @microsoft/sharepoint
Gulp serve

but when the browser opens i will get an empty screen instead of getting a SharePoint web part + the command line will return this error:-

Error - [webpack] WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

cisco – Ansible regex didn’t match command output – Empty list –

I’am trying to get the list of the device ID and the list of the port Id with ansible with regex but i get an empty list, below the output that i’am trying to parse it :

Device ID        Local Intrfce     Holdtme    Capability  Platform  Port ID
hello.fr.com #(this is in line separatly)
                 Fa 3/1/1         400             R S I    XXXX       Gi 3/3 #(and this in the next line)
cdp.fr.com
                 Fa 0/0/1         600            R S I     XXXX         Gi 3/3

Total cdp entries displayed : 2

and here my code:



tasks:
   - name: get neighbors
     ios_command:
       commands: 
         - show cdp neighbors
     register: output

   - set_fact: 
       reg_address: '(S+(.)S+(.)S+(.)S+)s+'
       reg_ports: 's+S+sS+s+d+s+wswsws+S+s+(S+sd+(/)d+)'

   - set_fact: 
       List_interfaces: ()
       List_ports: ()

   - set_fact: 
       List_interfaces: "{{List_interfaces + item | string | regex_search(reg_address, '\1') }}"
     loop: "{{output.stdout_lines(0)}}"
     when: "{{ List_interfaces | length }} > 0"
   - set_fact: 
       List_ports: "{{List_ports + item | string | regex_search(reg_ports, '\1') }}"
     loop: "{{ output.stdout_lines(0) }}"
     when: "{{ List_ports | length }} > 0"

javascript – How to match the question id in the nested table to the main table

const questionsData = useSelector((state) => state.questionsData)
useEffect(() => {
        dispatch(getQuestionsData())
    }, ())

const columns = (
        {
            title: 'Question No',
            dataIndex: 'key',
            key: 'question_no',
        },
        {
            title: 'Scenario',
            dataIndex: 'description',
            key: 'description',
            width: '25%',
        },
        {
            title: 'Total Marks',
            dataIndex: 'qn_total_mark',
            key: 'qn_total_mark',
        },
    )
const expandedRowRender = () => {
        const columns = (
            {
                title: 'Part Description',
                dataIndex: 'part_desc',
                key: 'key',
            },
        )
        return (
            <Table
                columns={columns}
                dataSource={questionsData}
            />
        )
    }

    return (
        <>
            <Table
                columns={columns}
                dataSource={questionsData}
                expandable={{ expandedRowRender }}
            />
        </>
    )
}

for question in questions:
        if question.question_id not in res:
            res(question.question_id) = {
                "key": question.question_id,
                "question": question.question,
                "description": question.description,
                "qn_total_mark":question.qn_total_mark,
                "part_desc": question.part_desc,
            }

what i am trying to do is create a nested table to store the part_desc , however my nested table right now gives back all the part desc regardless of the question number,is there a way to store the part description matching the question number respectively

google sheets – How to match and generate all corresponding data from a list

https://docs.google.com/spreadsheets/d/1GkwRr2zrmFhozxY2Vz0OqD8qC664ZsAyYFxxaOh6n3A/edit?usp=drivesdk

In this spreadsheet…I have scrape a webpage using =query( importhtml("https://chancesgames.com/WinningNumbers/WinningList", "table", 1), "select Col1, Col2, Col4, Col5 where Col1 is not null and toDate(Col1) >= date '" & text(B1, "yyyy-mm-dd") & "' and toDate(Col1) <= date '" & text(C1, "yyyy-mm-dd") & "' and lower(Col2) matches '.*(" & lower(D1) & ").*' ", 1 )

…it retrieved four columns off that page…which is in Shawn columns A2 :d…I subsequently I generated all possible combinations of the scraped data…using =ArrayFormula(Split(Flatten(Query(if(len(C3:C300),B3:B300&"@"&Split(RegexReplace(Transpose(Query(Transpose(Mid(text(C3:C300,"000")&",", {1,2,3,4,1,3,2,4,3,1,2,4,3,2,1,4,2,1,3,4,2,3,1,4},1)),,69))," ",""),","),),"Where Col1!='' ")),"@"))… To find and filter all possible combinations Divisible by 12,13,37,101, 111 to it’s lowest common multiple… The result from this filter is in column… Which was later filtered to retrieve all numbers between 0-100…once filtered, the formula =ARRAYFORMULA(if(AE3:AE="",,left(AE3:AE,1)&right(AE3:AE,1)&mid(AE3:AE,2,1))) was applied to generate the reverse of those numbers…which was then filtered in to sheet 2 of the spreadsheet. ..where this formula (arrayformula(if(a:a="",,a:a*{12,13,37,101,111) was applied and used to generate a series of values. These values was conditionally formatted to highlights duplicates against to list which is locate in column I and k of sheet2…

I am seeking…to match all data generated by arrayformula(if(a:a="",,a:a*{12,13,37,101,111) with the
matching states and 3/4 digit numbers which are in lists h3:I and j3:k in columns a:f….
Is that possible

duplicate – How could I use vlookup and countifs function to match data in google sheets?

I am scraping a webpage that contains digits and associated states…I have have broken those digits to it lowest common multiple…in the first sheet of this spreadsheet…and in sheet I have filter those result and applied a series of calcution using eg array(if(a:a=””,,a:a*{12,13,37,101,111}))…the result are in ranges A5:f of that sheet. Subsequently I conditionally formatted the digits in columns I and k respectfully to highlight duplicates in the range a5:f. I would like to have the names and corresponding digits appear in or be generated and highlighed in the range a5:f ..(possibly m5:q also) could someone assist? Thanks in advance

google sheets return cells if match in multiple columns

https://docs.google.com/spreadsheets/d/1PvGWPsBZ3NsqlVWVlmJaoP5kPKc01KM8knOSYMdU2dM/edit?usp=sharing

I have multiple columns of names (stocks from googlefinance) and if there is a match across the columns I need to return only the matches into a new column. I need to be able to do this for both two matches and three matches across the columns.

I have a sample google sheet above with sample columns and desired returns for illustration.

I have tried the following functions COUNTIF VLOOKUP QUERY, I cannot figure out how to search across all possibilities.

=IF(COUNTIF($B:$E, $A2:$A20)>0, $A2:$A20,””), returns only one match from the first column

=VLOOKUP($A2:$A20,$B2:$E50,1,true) only returns one match as well, the data isn’t sorted and if I use false I get no results.

=QUERY($A2:$E50, “select A where A matches B:E label A ‘Multis'” ) only returns results if they are in the corresponding cells i.e., A3=C3, not A3=C4

none of these can look to see if column B matches column C. If I could get any of these to work I could nest searches A, B:E; B, C:E; C, D:E; D, E; then concatenate the results and delete repeats. I have not been able to get the A, B:E to work correctly.

android – Error: Decoded digest length 48 does not match expected length for SHA-256 of 32

Estoy poniendo un archivo network_security_config.xml, en el pongo la sha256 al que quiero conectarme, pero obtengo un error de longitud.
alguien podria ayudarme?

Este es mi xml.

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="https://es.stackoverflow.com/@raw/server_cert" />
        </trust-anchors>
    </base-config>
    <domain-config>
        <domain includeSubdomains="true">https:ejemplo.com</domain>
        <trust-anchors>
            <certificates src="https://es.stackoverflow.com/@raw/server_cert"/>
        </trust-anchors>
        <pin-set expiration="2021-12-31">
            <pin digest="SHA-256">9c8kf8k7ee2bkb9dk81d2e5fofc2ke0c3c88o2k362fed23ko671f4732k113o3o=</pin>
        </pin-set>
    </domain-config>
</network-security-config>

pero cuando compilo me arroja el siguiente eeror

“C:UserAndroidplatformsandroidappsrcmainresxmlnetwork_security_config.xml:14: Error: Decoded digest length 48 does not match expected length for SHA-256 of 32 [NetworkSecurityConfig]
9c8kf8k7ee2bkb9dk81d2e5fofc2ke0c3c88o2k362fed23ko671f4732k113o3o
^