C conditional operator (‘?’) with empty second parameter [duplicate]
It is not permitted by the language C (as far as I know), but compilers such as gcc have the shortcut a?:c as an extension. a?:c means the same as a?a:c.
It is not permitted by the language C (as far as I know), but compilers such as gcc have the shortcut a?:c as an extension. a?:c means the same as a?a:c.
One way to achieve this with TF 0.12 onwards is to use dynamic blocks: dynamic “access_logs” { for_each = var.environment_name == “production” ? [var.environment_name] : [] content { bucket = “my-bucket” prefix = “${var.environment_name}-alb” } } This will create one or zero access_logs blocks depending on the value of var.environment_name.
In SQL, you do it this way: SELECT CASE WHEN @selectField1 = 1 THEN Field1 ELSE NULL END, CASE WHEN @selectField2 = 1 THEN Field2 ELSE NULL END FROM Table Relational model does not imply dynamic field count. Instead, if you are not interested in a field value, you just select a NULL instead and … Read more
TL;DR As of Python 3.10.0 (alpha6 released March 30, 2021), Python has an official syntactical equivalent called match. The basic syntax is: match value: case condition: action(s) … For older Python versions, there are only workarounds if you don’t want to resort to if–elif–else. See this excellent community post for a collection of some. Example … Read more
numpy.select This is a perfect case for np.select where we can create a column based on multiple conditions and it’s a readable method when there are more conditions: conditions = [ df[‘gender’].eq(‘male’) & df[‘pet1’].eq(df[‘pet2’]), df[‘gender’].eq(‘female’) & df[‘pet1’].isin([‘cat’, ‘dog’]) ] choices = [5,5] df[‘points’] = np.select(conditions, choices, default=0) print(df) gender pet1 pet2 points 0 male dog … Read more
You need to take out the $ signs before the row numbers in the formula….and the row number used in the formula should correspond to the first row of data, so if you are applying this to the (“applies to”) range $B$2:$B$5 it must be this formula =$B2>$C2 by using that “relative” version rather than … Read more
EDIT: Since Dart 2.2, new syntaxes supports this natively: Column( children: [ if (foo != null) Text(foo), Bar(), ], ); This problem is currently debated on github here. But for now, you can use dart sync* functions: Row( children: toList(() sync* { if (foo == 42) { yield Text(“foo”); } }), ); where toList is: … Read more
If a tag doesn’t exist, .find() indeed returns None. Simply test for that value: for event in root.findall(‘event’): party = event.find(‘party’) if party is None: continue parties = party.text children = event.get(‘value’) You already use .get() on event to test for the value the attribute; it returns None as well if the attribute does not … Read more
Use the timeits, Luke! Conclusion List comprehensions perform the best on smaller amounts of data because they incur very little overhead, even though they are not vectorized. OTOH, on larger data, loc and numpy.where perform better – vectorisation wins the day. Keep in mind that the applicability of a method depends on your data, the … Read more