parentheses

create a regex that knows balanced parenthesis with maximum depth of 5

create a regex that knows balanced parenthesis with maximum depth of 5 Question: I have a problem with a regex, it is supposed to match if the depth is between 1 or 5, for example it should match with “()()()”, “((((()))))”, “(()((()))())” and not match with “())()”, “(((((())))))” och “(x)”. I have this pattern = …

Total answers: 3

Why does del (x) with parentheses around the variable name work in Python?

Why does del (x) with parentheses around the variable name work in Python? Question: Why does this piece of code work the way it does? x = 3 print(dir()) #output indicates that x is defined in the global scope del (x) print(dir()) #output indicates that x is not defined in the global scope My understanding …

Total answers: 2

Indices of matching parentheses in Python

Indices of matching parentheses in Python Question: Is there a way to get indices of matching parentheses in a string? For example for this one: text = ‘aaaa(bb()()ccc)dd’ I’d like to get a dictionary with values: result = {4:14, 7:8, 9:10} which means that parentheses on index 4 and 14 are matching , 7 and …

Total answers: 5

What is the meaning of curly braces?

What is the meaning of curly braces? Question: Just starting to figure Python out. I’ve read this question and its responses: Is it true that I can't use curly braces in Python? and I still can’t fathom how curly braces work, especially since pages like Simple Programs: http://wiki.python.org/moin/SimplePrograms use curly braces all over the place. …

Total answers: 5

Parentheses in Python Conditionals

Parentheses in Python Conditionals Question: I have a simple question regarding the use of parentheses in Python’s conditional statements. The following two snippets work just the same but I wonder if this is only true because of its simplicity: >>> import os, socket >>> if ((socket.gethostname() == "bristle") or (socket.gethostname() == "rete")): … DEBUG = …

Total answers: 7

python assert with and without parenthesis

"assert" statement with or without parentheses Question: Here are four simple invocations of assert: >>> assert 1==2 Traceback (most recent call last): File “<stdin>”, line 1, in ? AssertionError >>> assert 1==2, “hi” Traceback (most recent call last): File “<stdin>”, line 1, in ? AssertionError: hi >>> assert(1==2) Traceback (most recent call last): File “<stdin>”, …

Total answers: 6