nested

Python: Nested Loop

谁说胖子不能爱 提交于 2020-01-04 05:33:17
问题 Consider this: >>> a = [("one","two"), ("bad","good")] >>> for i in a: ... for x in i: ... print x ... one two bad good How can I write this code, but using a syntax like: for i in a: print [x for x in i] Obviously, This does not work, it prints: ['one', 'two'] ['bad', 'good'] I want the same output. Can it be done? 回答1: >>> a = [("one","two"), ("bad","good")] >>> print "\n".join(j for i in a for j in i) one two bad good >>> for i in a: ... print "\n".join(i) ... one two bad good 回答2: List

Bash shell script Nested while loop with IFS

孤街浪徒 提交于 2020-01-04 05:16:28
问题 I'm trying to parse a set of csv files using bash shell script the files looks as below: File1: /tmp/test.txt key1,key1file.txt key2,key2file.txt key3,key3file.txt Files: /tmp/inter/key1file.txt abc,cdf,123,456 Files: /tmp/inter/key2file.txt abc,cdf,123,456 Files: /tmp/inter/key3file.txt abc,cdf,123,456 I've tried parsing these files using 2 while loops: while IFS="," read keycol keyfile do while IFS="," read keyval do echo "inside inner while loop" echo "$keycol|$keyval" done < "/tmp/inter/

Nested modules in AngularJS

早过忘川 提交于 2020-01-04 05:14:28
问题 I Have 2 differents AngularJs modules : a widgetContainer and a widget. A widget can be displayed as an independant application or be included into a widgetContainer. A widgetContainer contains 0-N widgets. If i try to boostrap the widget module into the widgetContainer, angular throw the following error : Error: [ng:btstrpd] App already bootstrapped with this element '<div id="childApp">' http://errors.angularjs.org/1.5.8/ng/btstrpd?p0=%26lt%3Bdiv%20id%3D%22childApp%22%26gt%3B I have

R - Help converting nested lists(?) to data.frame

独自空忆成欢 提交于 2020-01-04 04:38:09
问题 I need to import a .mat (Matlab) datafile into R and organize its contents as a data frame. While importing is straightforward by using the R.matlab package, the conversion to data frame shows to be hard since data gets originally organized in some awkward way. It looks like there are two nested lists. So far I haven't been able to convert it to a data frame. Here is what I have so far: # Download original flux file oldwd <- getwd() tmp <- tempdir() setwd(tmp) url <- 'https://dl

How to commit a git repo into a git repo (not submodule)

我与影子孤独终老i 提交于 2020-01-04 02:27:09
问题 When I try to add and commit a git repository into another git repository, git helpfully makes it into a submodule. What if I want to track and commit changes to that nested repository in the outer repo? I.e. I want the outer repository to track all the files in the nested repo's working tree as well as its .git directory. The use case here is that I want to maintain a git repository of my whole "projects" directory (many of which use git or another VCS) for versioned backups, as well as

Reshaping nested struct arrays to cell array having elements with different sizes

一曲冷凌霜 提交于 2020-01-04 02:19:05
问题 I have a similar question to my previous one. This time the form of the nested structure looks like this: Sizes = [2, 5, 8, 6, 3]; cells = 5; for i = 1:cells for j = 1:Sizes(i) a(i).b.c(j).d = rand(1,1); end a(i).b.Size = Sizes(i); end Again I would like to put all the d values of a(:).b.c(:) into a single cell array that contains 1 x cells cells. Here is my solution using cellfun but I would like to avoid this function: ab = [a.b]; abc = {ab.c}; abcd = cellfun(@(x) [x.d], abc, 'UniformOutput

Can a freemarker interpolation contain an interpolation?

南楼画角 提交于 2020-01-04 01:36:15
问题 Let's say I have Freemarker variable A that contains the name of another variable on the hash tree, say. "B." I'd like to use a to read the value of B so, for example, if B contained "C" I could tell Freemarker to output C using A: ${${A}} should result in the output of "C". Naturally, this doesn't work in Freemarker, but is there a way to accomplish this? 回答1: Use the .vars special variable, which is a hash (map) of the variables, and hence you can use the aHash[aKeyExpression] syntax: ${

Mocking nested properties with mock

只愿长相守 提交于 2020-01-03 08:22:07
问题 I have a function call that returns an object: r = Foo(x,y) where r has a rich set of nested properties. For example, I can access r.prop_a.prop_b.prop_c . I would like to mock Foo , such that a specific leaf property of r is modified, i.e. such that r.prop_a.prop_b.prop_c returns a value under my control: >> r = Foo(x,y) >> r.prop_a.prop_b.prop_c 'fish' >> # some mock magic patching of Foo is taking place here >> r = Foo(x,y) >> r.prop_a.prop_b.prop_c 'my_fish' I do not care about