nested

A Faster Nested Tuple to List and Back

三世轮回 提交于 2019-12-05 23:52:42
I'm trying to perform tuple to list and list to tuple conversions on nested sequences of unknown depth and shape. The calls are being made hundreds of thousands of times, which is why I'm trying to squeeze out as much speed as possible. Any help is much appreciated. Here's what I have so far... def listify(self, seq, was, toBe): temp = [] a = temp.append for g in seq: if type(g) == was: a(self.listify(g, was, toBe)) else: a(g) return toBe(temp) And a call for tuple to list would look like this: self.listify((...), tuple, list) Edit: Yeah, I totally missed both the enumerate (from an old

How to access controls inside a nested master page? why does it behave differently from content pages?

天大地大妈咪最大 提交于 2019-12-05 23:51:33
问题 Is there a difference between these two scenarios: (1) Accessing a property on a master page from a regular child (2) Accessing a property on a master page from a nested master page I tried to access a textbox in the master page from a content page like this: TextBox a; a = (TextBox)Master.FindControl("ayyash"); // Master is declared in MasterType directive defaultTextbox.Text = a.Text; // defaultTextBox is a textbox control inside default.aspx it works, but then when I applied the same

PHP - Create a nested array from MySQL data

扶醉桌前 提交于 2019-12-05 23:13:39
I have some data stored in a table like so: id parent_id name 1 0 Entry 1 2 0 Entry 2 3 0 Entry 3 4 1 Child of entry 1 I want to turn it into a nested array like so: array( array( 'id' => 1, 'parent_id' => 0, 'name' => 'Entry 1', 'children' => array(...) ), ... ); Ideally, it would need to support an infinite amount of nesting (children with children). Is my table set up to support this, if so, how would I generate this kind of array using the data in the table? If not, how should I set up my table? There is a very good description of managing hierarchical data in mysql here: managing

Writing nested dictionary (forest) of a huge depth to a text file

醉酒当歌 提交于 2019-12-05 23:08:39
I have a huge depth dictionary that represents forest (many non-binary trees) which I want to process the forest and create a text file with all possible relations of the forest, e.g. given the dictionary: {'a': {'b': {'c': {}, 'd': {}}, 'g': {}}} the generated text file will look like: a b c a b d a g Note that the nested dictionary is big and iterating over it recursively is makes a memory run-time error. What I tried doing is converting the dictionary into a list of lists recursively which yields a run-time error. The code: def return_list(forest): for ent in forest.keys(): lst = [new_ent]

Using ifelse Within apply

女生的网名这么多〃 提交于 2019-12-05 23:06:32
问题 I am trying to make a new column in my dataset give a single output for each and every row, depending on the inputs from pre-existing columns. In this output column, I desire "NA" if any of the input vales in a given row are "0". Otherwise (if none of the inputs are 0), I want the output for that row to be the number of unique values of the inputs. I thought that the solution would use an ifelse function nested within an apply function, but I get an error that I do not understand. data$output

Ordered list CSS style includes parent number

爱⌒轻易说出口 提交于 2019-12-05 22:20:34
We're looking to use CSS to create an ordered list that looks like this: A. A.1 A.2 B. C. C.1 C.2 C.2.1 C.2.2 How would you include the parent index in the child like this? Gabriele Petrioli You should use CSS counters W3C specs ( as @Zeta ) has pointed out, but here is an approach that will handle multiple nesting and latin counters .. ol{ list-style: none; } ol.roman{ counter-reset: roman; } ol.roman > li:before{ counter-increment: roman; content: counter(roman, upper-latin)"."; padding-right:5px; } ol.roman li ol{ counter-reset: inner; } ol.roman ol li:before{ counter-increment: inner;

* foreach inside foreach codeigniter 2?

你离开我真会死。 提交于 2019-12-05 22:05:36
In codeigniter 2.1 I'm trying to display channels by category. So if i have a category called Film, i should see a list of Channels within Film. I tried a nested foreach loop to accomplish this but can't seem to get it to work. My tables structure is something like this but more complicated: My model: <?php class Pages_model extends CI_Model { function get_channels_by_categ_tv() { $this->db->select('categories.category_name, channels.channel_name'); $this->db->from('type_categ'); $this->db->join('categories', 'categories.category_id = type_categ.category_id'); $this->db->join('channels',

How to read a file to a list of lists?

蹲街弑〆低调 提交于 2019-12-05 21:09:15
I want to create a list of lists from a file that contains the following data: 101 Rahul 102 Julie 103 Helena 104 Kally CODE lis = [] with open("student_details.txt" , "r+") as f: for i in range(1,3,1): for data in f.read().split(): lis.append(data) print(lis) Output I Want [[101,Rahul] ,[102,Julie] ,[103,Helena] ,[104,Kally]] Output I m getting ['101', 'Rahul', '102', 'Julie', '103', 'Helena', '104', 'Kally'] Your code: lis = [] with open("student_details.txt" , "r+") as f: for i in range(1,3,1): for data in f.read().split(): lis.append(data) print(lis) Note the two for loops, what you are

Efficient sampling from nested lists

我只是一个虾纸丫 提交于 2019-12-05 19:29:49
问题 I have a list of lists , containing data.frames, from which I want to select only a few rows . I can achieve it in a for-loop, where I create a sequence based on the amount of rows and select only row indices according to that sequence. But if I have deeper nested lists it doesn't work anymore. I am also sure, that there is a better way of doing that without a loop. What would be an efficient and generic approach to sample from nested lists, that vary in their dimensions and contain data

How to do Nested For Loops in Functional Style

泪湿孤枕 提交于 2019-12-05 19:18:47
I'm in the process of learning functional programming, and completely getting rid of for loops has been a challenge sometimes, because they provide so much control and freedom. Below is an example of checking if a string is an isogram or not (no letters should be repeated). With nested for loops, it became an easy solution. Is there a way to do this the functional way with any high order functions or anything else? Any suggestion would be a huge help. Code: function isIsogram(string) { let array = string.split(''); let condition = true; for (let i = 0; i < string.length; i++) { //first loop