PHP conditionals, brackets needed?

you can do if else statements like this: <?php if ($something) { echo ‘one conditional line of code’; echo ‘another conditional line of code’; } if ($something) echo ‘one conditional line of code’; if ($something) echo ‘one conditional line of code’; echo ‘a NON-conditional line of code’; // this line gets executed regardless of the … Read more

Get the string within brackets in Python

How about: import re s = “alpha.Customer[cus_Y4o9qMEZAugtnW] …” m = re.search(r”\[([A-Za-z0-9_]+)\]”, s) print m.group(1) For me this prints: cus_Y4o9qMEZAugtnW Note that the call to re.search(…) finds the first match to the regular expression, so it doesn’t find the [card] unless you repeat the search a second time. Edit: The regular expression here is a python … Read more

Different meanings of brackets in Python

Square brackets: [] Lists and indexing/lookup/slicing Lists: [], [1, 2, 3], [i**2 for i in range(5)] Indexing: ‘abc'[0] → ‘a’ Lookup: {0: 10}[0] → 10 Slicing: ‘abc'[:2] → ‘ab’ Parentheses: () (AKA “round brackets”) Tuples, order of operations, generator expressions, function calls and other syntax. Tuples: (), (1, 2, 3) Although tuples can be created … Read more

Flatten list of lists [duplicate]

Flatten the list to “remove the brackets” using a nested list comprehension. This will un-nest each list stored in your list of lists! list_of_lists = [[180.0], [173.8], [164.2], [156.5], [147.2], [138.2]] flattened = [val for sublist in list_of_lists for val in sublist] Nested list comprehensions evaluate in the same manner that they unwrap (i.e. add … Read more