Could it be simplified in CoffeeScript:
redisSETNXReply.toString() == '1' or redisSETNXReply.toString() =='0'
to something like:
redisSETNXReply.toString() == '1' or '0'
?
You could do this:
redisSETNXReply.toString() in ['1', '0']
Related
I can do this using an if statement but I feel like the code is too long for this simple operation.
num = -12345
-->inserts magical code<--
desired output
num_list = ['-1', '2', '3', '4', '5']
You can simply use .split("\\B")
So the magical code would be:
String[] num_list = Integer.toString(num).split("\\B");
I have two values e.g a=972 and b=11188.
I want to get the details of all entries from a tab delimited text file which lies in between both numbers. The python comparison operators <= and >= are returning wrong results.
I have used the <= and >= operators in the if statement.
if l1[3]<="18188" >="900" and l1[2]=="1":
and it is returning nothing.
when I write
if l1[3]<="18188":
it returns "18166 and 11188 as output". I ideally this if function must return "11188 ,972 and 3632".
This is the tab delimited file.
SRR6298199.1 16 1 3632 0 50M32S * 0 0 AACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCC !!""""!"!"!"!!"!!!""""""!!!""""!"" NM:i:1 AS:i:48 XS:i:47
SRR6298199.10 0 1 972 0 40M274S * 0 0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATCAATTTGAA !"""'$""!"!"""" NM:i:0 AS:i:40 XS:i:40 XP:Z:3,+18166143,41S36M237S,0,0;
SRR6298199.10 0 1 18166 0 41S36M237S * 0 0 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATCAATTT !"""!#!#$#$"!"""" NM:i:0 AS:i:36 XS:i:34 XP:Z:2,+9723273,40M274S,0,0;
SRR6298199.11 16 1 11188 0 1841S9M * 0 0 GACCAGTATCGGGCCGGCATAAGCCTCGAATTTCACCAGCA !!!!!!""!#!"%%&)(%-//.//,".,.+.-..&! NM:i:18 AS:i:81 XS:i:81
Here is the complete code.. please figure out why this code is not returning true results.
# EXTRACTING THE DETAILS OF READS ALIGNED ON CHR_1
fr=open("Sample.txt","r")
z=fr.read()
bz=z.split("\n")
temp1=[]
for bases in bz:
temp1.append(bases.split("\t"))
cc1=[]
se=[] #READ NAMES ALIGNED ON CHR_1
chr2=[] #READ NAMES ALIGNED ON CHR_2
for l1 in temp1:
if l1[3]<="18188" >="900" and l1[2]=="1":
#print(l1[3])
#cc1.append("#"+str(l1[0])+"\t"+"length="+str(len(l1[9]))+"\n"+l1[9]+"\n"+"+"+l1[0]+"\t"+"length="+str(len(l1[9]))+"\n"+l1[10])
cc1.append("#"+str(l1[0])+" "+"/1"+"\n"+"+"+"\n"+l1[9])
print(cc1)
I expect the output of if l1[3]<="18188" >="900" and l1[2]=="1": to be
['SRR6298199.1', '16', '1', '3632', '0', '50M32S', '*', '0', '0', 'AACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCC', '!!""""!"!"!"!!"!!!""""""!!!""""!""', 'NM:i:1', 'AS:i:48', 'XS:i:47']
['SRR6298199.10', '0', '1', '972', '0', '40M274S', '*', '0', '0', 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATCAATTTGAA', '!"""\'$""!"!""""', 'NM:i:0', 'AS:i:40', 'XS:i:40', 'XP:Z:3,+18166143,41S36M237S,0,0;']
['SRR6298199.11', '16', '1', '11188', '0', '1841S9M', '*', '0', '0', 'GACCAGTATCGGGCCGGCATAAGCCTCGAATTTCACCAGCA', '!!!!!!""!#!"%%&)(%-//.//,".,.+.-..&!', 'NM:i:18', 'AS:i:81', 'XS:i:81']
['SRR6298199.10', '0', '1', '18166', '0', '41S36M237S', '*', '0', '0', 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATCAATTT', '!"""!#!#$#$"!""""', 'NM:i:0', 'AS:i:36', 'XS:i:34', 'XP:Z:2,+9723273,40M274S,0,0;']
but aforementioned if statement is returning [], an empty list
Two problems:
1) you misuse / misorder the comparisonoperators
if l1[3]<= "18188" >="900" and l1[2]=="1": # always false becase "1..." is never >= "9.."
should most probably be
if "900"<= l1[3] <="18188" and l1[2]=="1":
2) you use lexicografical comparison to compare numbers - this will fail because in lexicographical comparisons "9" is bigger then "1111111"
You can fix both errors using correct comparison syntax and float-values for comparison:
if 900 <= float(l1[3]) <= 18188 and l1[2]=="1":
I have a list, where I want to group the repeating objects into a single object in the new list. Basically, convert this:
s = ['0.352125', '1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0.241041', '0.313429', '1', '1']
to this:
s_new = ['0.352125', '4*1','8*0', '0.241041', '0.313429','2*1']
I have tried itertools.groupby() function (python 2.7) as below:
from itertools import groupby
s_g = [list(g) for k, g in groupby(s)]
s_new = [', '.join('{}*{}'.format(sum(1 for _ in g), k) for k, g in groupby(s_g))]
As a result, I get:
s_new = ["1*['0.352125'], 1*['1', '1', '1', '1'], 1*['0', '0', '0', '0', '0', '0', '0', '0'], 1*['0.241041'], 1*['0.313429'], 1*['1', '1']"]
Apparently, this is not the list format I'm trying to get. Could someone please help me with this?
You unnecessarily applied groupby twice and there's also no reason to use str.join.
You can use the following list comprehension instead:
['%s*' % len(l) * (len(l) > 1) + k for k, g in groupby(s) for l in (list(g),)]
Any idea what is the difference betweet this:
p_persist_reg_CRC_calc: process (Clk_50Mhz)
begin
if falling_edge(Clk_50Mhz) then
if crc_rx_init <= '0' then
flash_crc_calc <= (others =>'1');
else
flash_crc_calc <= (others =>'0');
end if;
end if;
end process p_persist_reg_CRC_calc;
and this:
p_persist_reg_CRC_calc: process (Clk_50Mhz)
begin
if falling_edge(Clk_50Mhz) then
if crc_rx_init <= '1' then
flash_crc_calc <= (others =>'0');
else
flash_crc_calc <= (others =>'1');
end if;
end if;
end process p_persist_reg_CRC_calc;
The second stack to zero.
In my understanding they should be the same as function.
Regards,
Emil
Most likely a typo: try
if crc_rx_init = '1' then
( '0' and '1' are both <= '1' )
Assuing crc_rx_init is a std_logic, then the only difference is likely in simulation.
Remember, std_logic has 9 states ('U', '0', '1', 'X', 'Z', 'L', 'H', 'W', '-'). In the first case, if crc_rx_init was 'U', then flash_crc_calc would be all '0'. In the second case, flash_crc_calc would be all '1'.
How can I use regex with if-condition in sqlite? My query below,
....
WHERE DATE(localdate) BETWEEN '2014-10-09' AND '2015-05-12'
AND n.nid = '9'
AND CASE WHEN '9' REGEXP '^[0-9]+$' THEN w.wspdi != '-9999' ELSE w.wspdi != NULL END
error,
no such function: REGEXP
Any ideas?