Categories
Mastering Development

Constraint randomization of two dimensional array

I am looking for some solution of a problem i.e. I have a two dimensional constraint. One is typedef struct { rand int subcarriers[12]; } symbol_alloc_per_prb_t; class stim_gen_c; //Declaration of variables rand int prb; rand symbol_alloc_per_prb_t symb_alloc_prbs[]; rand int channel; constraint c_ch {channel inside {[0:127]};} constraint c_prb {prb inside {[0:272]};} constraint c_symb_alloc { symb_alloc_prbs.size() == […]

Categories
Mastering Development

How to get words matches with it’s count using pandas

i have 2 Dataframes like set1 = [‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’] set2 = [‘a’,’b’,’b’,’c’,’c’,’f’,’h’,’j’,’k’] df1 = pd.DataFrame(set1, columns=[‘name’]) df2 = pd.DataFrame(set2, columns=[‘name’]) i want to compare these 2 Dataframes without forloop and get a output like df3 = [‘a=1′,’b=2′,’c=2′,’f=1′,’h=1′,’j=1’] which way i can use for getting this output any examples .?? here i want only the items from […]

Categories
Mastering Development

How to create a table using a list of lists

I’m trying to write a file where you have 2 rows, with the first row being numbers and the 2nd row being letters. As an example, I was trying to do this with the alphabet. list1=[‘A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’,’K’,’L’,’M’,’N’,’O’,’P’,’Q’,’R’,’S’,’T’,’U’,’V’,’W’,’X’,’Y’,’Z’] list2=list1+list1 abcList = [[],[]] for i in range(len(list2)): i+=1 if i % 5 == 0: if i>=10: abcList[0].append(str(i) + […]

Categories
Mastering Development

Creating a hierarchical dictionary with nested lists or dictionaries from 2 lists

I have 2 lists. The first has number denoting what part of the hierarchy that the value in the other list at the same index belongs. I am trying to get dynamic code that could theoretically go to any number of steps. The first 3 work correctly but when I had more steps to the […]

Categories
User Help Web Apps

Google sheets: How do I convert rows with 45 columns into 15 separate rows, each with 3 columns?

I am working with a google sheet that gets data from an email parser. Each time an email comes in, a single row is created, and fills in these columns: B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, […]

Categories
Mastering Development

same regex gives different results

It’s probably not the same but I can’r really see the difference. In the first one the function finds substring which start with "#" sign: title= re.findall(r"[#]([^#@$\\|]*)(?=[#¿@$\\|]|$)", c) And then it also uses regex to transform what it found: c = re.sub("[#]({})(?=[¿#@$\\|]|$)".format(i,),"¿<a class=’title-link’ href=’/titles/{}–{}’>{}</a>{}".format(url,title.id,j,rest),c) The ones above work just fine, they find the substrings and […]

Categories
Mastering Development

Is there a method to convert a letter into it’s index in a tuple in python?

What I mean by the question is if i had: alphabet:["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] and received an input of "a" I would get back an index of 1, or z to get back an index of 26, from the tuple’s index. I’m wondering if there is an easier way instead of using a dictionary. So like if I […]

Categories
Mastering Development

How does Python’s random.shuffle() alter the value of a list without returning anything and is this something any Python coder can do as well? [duplicate]

I just noticed I wasn’t getting a return from random.shuffle(). I realised this makes sense as you would logically want to work with the original list unless specified otherwise. >>> import string >>> import random >>> letters = list(string.ascii_lowercase) >>> print(letters) [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, […]

Categories
Mastering Development

why is this dynamic programming answer slow?

Why is this solution slow? I’m guessing it’s because the sub-problems are not solved at the right time when they should be. What am I doing wrong? def longest_palindrome(s) len = s.length longest_start = 0 longest_end = 0 mem = Array.new(len) { Array.new(len, -1) } (0..(len – 1)).each do |i| (i..(len – 1)).each do |j| […]

Categories
Mastering Development

head(data) and data[“rowname”, ] not showing the same results

The following is the first few lines of my script: library(tidyverse) library(caret) # Read and clean up the data ugriz <- read.table( "F:/Users/Jeremy Moss/Dropbox/Astro at VUW/PhD stuff/data_files/optical_data/QSOs_1st_50k.dat-mags.dat") ugriz[ugriz == -999] <- NA fields <- c(‘name’, ‘z’,’delta_z’,’NED_class’,’SDSS_class’,’no_radio’,’radio_max’,’no_UV’, ‘UV_min’, ‘u’, ‘g’, ‘r’, ‘i’, ‘z_mag’, ‘I’, ‘J’, ‘H’, ‘K’, ‘W1’, ‘SPIT_5’, ‘W2’, ‘SPIT_8’, ‘W3’, ‘W4’, ‘NUV’, ‘FUV’) names(ugriz) […]