Python

Room rules: sopython.com/chatroom Code formatting guide: tinyu...
May 4, 2023 12:12
No. It is not matching for these - 1222.423525, 5572582582955245, 35E+767TYUU, GJKK5659857E+767E+ETYUU . I mean non scientific notation numbers
May 4, 2023 10:50
I must be doing something wrong here
May 4, 2023 10:49
Tried this - r'^(\d*(\.)?(\d+)?(?![eE])[-+]?\d+)$'. But it did not work for my use case
May 4, 2023 10:47
I tried negative lookahead (as in (?!...)) with an existing pattern to negate it. Could not come up with proper expression.
May 4, 2023 10:43
Is it possible to come up with something like "not matching regex"? I mean negation of regex that I have provided here?
May 4, 2023 10:38
problem here is to find all strings that does contain scientific notation number in it
May 4, 2023 10:37
Tested it. It just matches scientific notation numbers
May 4, 2023 10:36
I need to solve it using regex. This regex does that! r'^(\d*(\.)?(\d+)?[eE][-+]?\d+)$'
May 4, 2023 10:33
it can any string other than scientific notation of any number!
May 4, 2023 10:06
1222.423525, 5572582582955245, 35E+767TYUU, GJKK5659857E+767E+ETYUU --> Any of these should match
May 4, 2023 09:29
This regex r'^(\d*(\.)?(\d+)?[eE][-+]?\d+)$' matches all these strings 1.79E+16, 1.2e5, 1e-5, 1.e+1 . But for me full string should not be any of these : 1.79E+16, 1.2e5, 1e-5, 1.e+1. I need a solution using regex itself!
Sep 5, 2022 09:13
@MisterMiyagi Thank you
Sep 5, 2022 09:05
In this line- [*print_nested_keys(d)] , what does the * indicates?
Sep 5, 2022 09:04
Basically it is printing all the keys from dict
Sep 5, 2022 09:04
>>> [*print_nested_keys(d)] # Here, d is your nested dictionary
['Name1.NNum',
'Name1.NNumNode1.SubNodeA',
'Name1.NNumNode1.SubNodeASubNodeB',
'Name1.NNumNode1.Node2.SubNodeA',
'Name1.NNumNode1.Node2.SubNodeASubNodeD',
'Name1.NNumNode1.Node2.SubNodeASubNodeDSubNodeE',
'Name1.NNumNode1.Node2.Node3.child1',
'Name1.NNumNode1.Node2.Node3.child1child2.grandchild.greatgrandchild1',
'Name1.NNumNode1.Node2.Node3.child1child2.grandchild.greatgrandchild1greatgrandchild2']
Sep 5, 2022 09:04
def print_nested_keys(dic,path=''):
    for k,v in dic.items():
        if isinstance(v,dict):
            path+=k+"."
            yield from print_nested_keys(v,path)
        else:
            path+=k
            yield path
Sep 3, 2022 20:41
@PeterT %22my%20name%20/%20your%20name%22
Sep 3, 2022 20:35
@PeterT Using Postman it works!
Sep 3, 2022 20:35
@roganjosh It is indeed a GET request!
Sep 3, 2022 20:34
Same error
Sep 3, 2022 20:34
But it is not working as well
Sep 3, 2022 20:34
@PeterT Tried that already. The new value looks like this - > my+name+%2F+your+name
Sep 3, 2022 20:14
If I use name="your name \/ my name", I get the same error
Sep 3, 2022 20:13
Tried! No luck!
Sep 3, 2022 20:10
Do I need the escape this forward slash in query param?
Sep 3, 2022 20:09
Hello, I am trying to execute GET request using requests module. URL is something like this with query param - abc.com?name="your name / my name". I get this error for the same- "Message":"The requested resource does not support http method \'GET\'."
Jul 5, 2022 15:15
u = {'foo': [], 'bar': ['hi']}
# expected_output = {'foo': {'errors': [], 'error_count': 0}, 'bar': {'errors': ['hi'], 'error_count': 1}}
a = collections.defaultdict(dict)
for key in u:
    a[key]["errors"] = list(u[key])
    a[key]["error_count"] = len(a[key]["errors"])

print(a)
Jul 5, 2022 15:15
@MisterMiyagi ,@Aran-Fey This one?
Jul 5, 2022 14:51
u = {'foo': [], 'bar': ['hi']}
# expected_output = {'foo': {'errors': [], 'error_count': 0}, 'bar': {'errors': ['hi'], 'error_count': 1}}

a = collections.defaultdict(dict)
for key in u:
    a[key]["errors"] = []
    a[key]["error_count"] = 0

print(a)
Jul 5, 2022 14:51
@Aran-Fey Sorry for the late reply. Went out for some personal work. Here is the solution for final challange:
Jul 5, 2022 11:52
h = {'x': 1, 'y': 2}
for key in h:
    h[key] = str(h[key])
print(h)
Jul 5, 2022 11:48
Okay
Jul 5, 2022 11:47
h = {'x': 1, 'y': 2}
h['x'] = str(h['x'])
h['y'] = str(h['y'])
print(h)
Jul 5, 2022 11:47
Answer to challange 2:
Jul 5, 2022 11:33
z = ['foo', 'bar']
out = {'errors': ['foo', 'bar'], 'err_count': 2}

b = {"errors": z, "err_count": len(z)}
Jul 5, 2022 11:33
Solution for the challnge -
Jul 5, 2022 11:33
I was trying to solve the original problem till now ! Couldn't solve it yet!
Jul 5, 2022 11:01
Giving a try! Give me some time!
Jul 5, 2022 10:59
messages_by_tenant[message['tenant_name']['errors']].append(message['message'])
Jul 5, 2022 10:58
Getting - TypeError: string indices must be integers for
Jul 5, 2022 10:57
import collections

messages_by_tenant = collections.defaultdict(list)
for message in messages:
    messages_by_tenant[message['tenant_name']['errors']].append(message['message'])
Jul 5, 2022 10:57
Tried something like this:
Jul 5, 2022 10:50
As you can see I need to do slight modifictaion in the expected output.
Jul 5, 2022 10:49
defaultdict(<class 'list'>, {'test1': ['test message1', 'test message4', 'test message5'], 'test2': ['test message2', 'test message3']})
Jul 5, 2022 10:49
Output it produce is
Jul 5, 2022 10:49
messages_by_tenant = collections.defaultdict(list)
for message in messages:
    messages_by_tenant[message['tenant_name']].append(message['message'])
Jul 5, 2022 10:48
Yes. This is answer I received.
Jul 5, 2022 10:47
Challange is how to form that required output dictionary?
Jul 5, 2022 10:45
g = {
    "test1": {
        "errors": [
            "test message1",
            "test message4",
            "test message5"
        ],
        "err_count": 3
    },
    "test2": {
        "errors": [
            "test message2",
            "test message3",
        ],
        "err_count": 2
    }
}
Jul 5, 2022 10:45
Required output: