case

Is there any value to a Switch / Case implementation in Python?

怎甘沉沦 提交于 2019-12-05 21:26:51
Recently, I saw some discussions online about how there is no good "switch / case" equivalent in Python. I realize that there are several ways to do something similar - some with lambda, some with dictionaries. There have been other StackOverflow discussions about the alternatives. There were even two PEPs (PEP 0275 and PEP 3103) discussing (and rejecting) the integration of switch / case into the language. I came up with what I think is an elegant way to do switch / case. It ends up looking like this: from switch_case import switch, case # note the import style x = 42 switch(x) # note the

SQL WHERE depending on day of week

て烟熏妆下的殇ゞ 提交于 2019-12-05 20:55:43
I have a requirement to check records up to differing dates, depending on which day of the week it is currently. On a Friday I need for it to look at the entire next week, until Sunday after next. On any other day it should check the current week, up until the coming Sunday. I have the below currently but it's not working due to syntax error. Is it possible to do a CASE WHEN inside a WHERE clause? WHERE T0.[Status] IN ('R','P') AND CASE WHEN DATEPART(weekday,GETDATE()) = '5' THEN T0.[DueDate] >= GETDATE() AND <= DATEADD(day, 15 - DATEPART(weekday, GetDate()), GetDate()) WHEN DATEPART(weekday,

Coq case analysis and rewrite with function returning subset types

只愿长相守 提交于 2019-12-05 19:25:04
I was working is this simple exercise about writing certified function using subset types. The idea is to first write a predecessor function pred : forall (n : {n : nat | n > 0}), {m : nat | S m = n.1}. and then using this definition give a funtion pred2 : forall (n : {n : nat | n > 1}), {m : nat | S (S m) = n.1}. I have no problem with the first one. Here is my code Program Definition pred (n : {n : nat | n > 0}) : {m : nat | S m = n.1} := match n with | O => _ | S n' => n' end. Next Obligation. elimtype False. compute in H. inversion H. Qed. But I cannot workout the second definition. I

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS nested case statements

夙愿已清 提交于 2019-12-05 19:00:40
I am trying to create a query that gets the number of hours an event was open below is my query. I am using case statements because it needs to take into account to only count weekdays. This is a step in the process my overall goal is to actually get the hours for those days. So for example if the the days is more than one count all those days and multiply by 8.. if its less than one do a datediff hours and just get the hours for that day.. Any help would be greatly appreciated! but I am getting the following error: Only one expression can be specified in the select list when the subquery is

Is there a function to find all lower case letters in a character vector?

偶尔善良 提交于 2019-12-05 18:33:59
I just wrote one, but I was wondering if one already exists in R. Here's the function BTW (suggestions for improvement are welcome): set.seed(50) x <- sample(c(letters, LETTERS), 7) is.lower <- function(x) { unlist(sapply(x, function(x2) {x2 %in% letters})) } is.lower(x) grepl("[a-z]",x) for example? > grepl("[a-z]",x) [1] FALSE TRUE TRUE FALSE TRUE TRUE FALSE And why make it difficult? > x %in% letters [1] FALSE TRUE TRUE FALSE TRUE TRUE FALSE No need to make your own function. Another approach with the values instead of a logical index as the result, would be to name the letters as

C - Switch with multiple case numbers

夙愿已清 提交于 2019-12-05 12:32:47
问题 So my professor asked us to create a switch statement. We are allowed to use only the "SWITCH" statement to do the program. He wants us to input a number and then display it if it is on the number range and what briefcase number will be taken as shown below. Now... I know that for this type of program it is easier to use the IF statement . Doing Case 1: Case 2: Case 3...Case 30 will work but will take too much time due to the number range. #include <stdio.h> main() { int x; char ch1; printf(

Erlang : nested cases

强颜欢笑 提交于 2019-12-05 11:23:26
I'm very new to Erlang. I tried to find out if a list index is out of bounds (before trying it) so i wanted to do an if clause with something like if lists:flatlength(A) < DestinationIndex .... I discovered that those function results cannot be used in if guards so i used case instead. This results in a nested case statement case Destination < 1 of true -> {ok,NumberOfJumps+1}; false -> case lists:flatlength(A) < Destination of true -> doSomething; false -> case lists:member(Destination,VisitedIndices) of true -> doSomething; false -> doSomethingElse end end end. I found this bad in terms of

Case when a value is different to other value, SQL Server

匆匆过客 提交于 2019-12-05 09:19:07
问题 I have this table structure for table prices : CREATE TABLE prices ( id int, priceFrom int, priceUp int ); INSERT INTO prices (id, priceFrom, priceUp) VALUES (1, 23, 23), (2, 0, 0), (3, 12, 13), (4, 40, 40), (5, 15, 15), (6, 0, 0); This is the result: I have this query: select pricefrom, priceup, case when pricefrom = 0 then null when priceFrom <> priceUp then priceFrom + ' - ' + priceUp when priceFrom = priceUp then priceFrom end as FinalPrice from prices what I need is to do a case when

C# Switch-case string starting with

纵饮孤独 提交于 2019-12-05 08:25:05
问题 Is there any way to make a case condition in a switch statement where you say if a string begins with something? ex Switch (mystring) { case("abc")://String begins with abc (abcd or abc1 or abcz or abc.. or abc will fall in this condition). //Do Something break; default: break; } UPDATE Other strings can be different length. abc.. abczyv dcs2. qwerty as...k 回答1: If you knew that the length of conditions you would care about would all be the same length then you could: switch(mystring

How to use a case statement to determine which field to left join on

て烟熏妆下的殇ゞ 提交于 2019-12-05 06:04:48
I have a query that needs to be able to left join a field at the right place given the condition that the field is equal to a variable. Something like: CASE WHEN challenges.userID = $var LEFT JOIN challengesRead ON challenges.userID = challengesRead.userID CASE WHEN challenges.opponentID = $var LEFT JOIN challengesRead ON challenges.opponentID = challengesRead.userID I think I am on the right track but I'm not sure how to put the query together. Thanks Something like this may work LEFT JOIN challengesRead ON challenges.userID = CASE WHEN challenges.userID = $var THEN challengesRead.userID WHEN