flatten

How to copy certain files (w/o folder hierarchy), but do not overwrite existing files?

落爺英雄遲暮 提交于 2019-11-28 05:33:32
I need to copy all *.doc files (but not folders whose names match *.doc ) from a network folder \\server\source (including files in all nested folders) to a local folder C:\destination without preserving the nested folders hierarchy (i.e. all files should go directly into C:\destination and no nested folders should be created in C:\destination ). In case there are several files with the same name from different subfolders of \\server\source , only the first one should be copied and never overwritten then — all conflicting files found later should be skipped (there could be many cases like this

How to flatten a list of nested tuples in Python?

China☆狼群 提交于 2019-11-28 04:59:52
问题 I have a list of tuples that looks like this: [('a', 'b'), ('c', 'd'), (('e', 'f'), ('h', 'i'))] I want to turn it into this: [('a', 'b'), ('c', 'd'), ('e', 'f'), ('h', 'i')] What is the most Pythonic way to do this? 回答1: one-line, using list comprehension: l = [('a', 'b'), ('c', 'd'), (('e', 'f'), ('h', 'i'))] result = [z for y in (x if isinstance(x[0],tuple) else [x] for x in l) for z in y] print(result) yields: [('a', 'b'), ('c', 'd'), ('e', 'f'), ('h', 'i')] this is artificially creating

Flatten a javascript object to pass as querystring

雨燕双飞 提交于 2019-11-27 18:56:15
I have a javascript object that I need to flatten into a string so that I can pass as querystring, how would I do that? i.e: { cost: 12345, insertBy: 'testUser' } would become cost=12345&insertBy=testUser I can't use jQuery AJAX call for this call, I know we can use that and pass the object in as data but not in this case. Using jQuery to flatten to object would be okay though. Thank you. You want jQuery.param : var str = $.param({ cost: 12345, insertBy: 'testUser' }); // "cost=12345&insertBy=testUser" Note that this is the function used internally by jQuery to serialize objects passed as the

Perl: What is the easiest way to flatten a multidimensional array?

回眸只為那壹抹淺笑 提交于 2019-11-27 17:35:57
问题 What's the easiest way to flatten a multidimensional array ? 回答1: Using List::Flatten seems like the easiest: use List::Flatten; my @foo = (1, 2, [3, 4, 5], 6, [7, 8], 9); my @bar = flat @foo; # @bar contains 9 elements, same as (1 .. 9) Actually, that module exports a single simple function flat , so you might as well copy the source code: sub flat(@) { return map { ref eq 'ARRAY' ? @$_ : $_ } @_; } You could also make it recursive to support more than one level of flattening: sub flat { #

How to flatten a hetrogenous list of list into a single list in python?

∥☆過路亽.° 提交于 2019-11-27 15:45:55
I have a list of objects where objects can be lists or scalars. I want an flattened list with only scalars. Eg: L = [35,53,[525,6743],64,63,[743,754,757]] outputList = [35,53,525,6743,64,63,743,754,757] P.S. The answers in this question does not work for heterogeneous lists. Flattening a shallow list in Python Here is a relatively simple recursive version which will flatten any depth of list l = [35,53,[525,6743],64,63,[743,754,757]] def flatten(xs): result = [] if isinstance(xs, (list, tuple)): for x in xs: result.extend(flatten(x)) else: result.append(xs) return result print flatten(l) it

How to flatten array in jQuery?

孤街浪徒 提交于 2019-11-27 13:00:20
How to simply flatten array in jQuery? I have: [1, 2, [3, 4], [5, 6], 7] And I want: [1, 2, 3, 4, 5, 6, 7] You can use jQuery.map , which is the way to go if you have the jQuery Library already loaded. $.map( [1, 2, [3, 4], [5, 6], 7], function(n){ return n; }); Returns [1, 2, 3, 4, 5, 6, 7] Use the power of JavaScript: var a = [[1, 2], 3, [4, 5]]; console.log( Array.prototype.concat.apply([], a) ); //will output [1, 2, 3, 4, 5] Here's how you could use jquery to flatten deeply nested arrays: $.map([1, 2, [3, 4], [5, [6, [7, 8]]]], function recurs(n) { return ($.isArray(n) ? $.map(n, recurs):

How to deserialize JSON into flat, Map-like structure?

百般思念 提交于 2019-11-27 12:50:30
Have in mind that the JSON structure is not known before hand i.e. it is completely arbitrary, we only know that it is JSON format. For example, The following JSON { "Port": { "@alias": "defaultHttp", "Enabled": "true", "Number": "10092", "Protocol": "http", "KeepAliveTimeout": "20000", "ThreadPool": { "@enabled": "false", "Max": "150", "ThreadPriority": "5" }, "ExtendedProperties": { "Property": [ { "@name": "connectionTimeout", "$": "20000" } ] } } } Should be deserialized into Map-like structure having keys like (not all of the above included for brevity): port[0].alias port[0].enabled port

How to flatten a pandas dataframe with some columns as json?

做~自己de王妃 提交于 2019-11-27 11:14:04
问题 I have a dataframe df that loads data from a database. Most of the columns are json strings while some are even list of jsons. For example: id name columnA columnB 1 John {"dist": "600", "time": "0:12.10"} [{"pos": "1st", "value": "500"},{"pos": "2nd", "value": "300"},{"pos": "3rd", "value": "200"}, {"pos": "total", "value": "1000"}] 2 Mike {"dist": "600"} [{"pos": "1st", "value": "500"},{"pos": "2nd", "value": "300"},{"pos": "total", "value": "800"}] ... As you can see, not all the rows have

Flatten Adjacency List Hierarchy To A List Of All Paths

喜欢而已 提交于 2019-11-27 10:03:55
问题 I have a Table that stores Hierarchical information using the Adjacency List model. (uses a self referential key - example below. This Table may look familiar): category_id name parent ----------- -------------------- ----------- 1 ELECTRONICS NULL 2 TELEVISIONS 1 3 TUBE 2 4 LCD 2 5 PLASMA 2 6 PORTABLE ELECTRONICS 1 7 MP3 PLAYERS 6 8 FLASH 7 9 CD PLAYERS 6 10 2 WAY RADIOS 6 What is the best method to "flatten" the above data into something like this? category_id lvl1 lvl2 lvl3 lvl4 ----------

Scala - convert List of Lists into a single List: List[List[A]] to List[A]

我是研究僧i 提交于 2019-11-27 09:00:43
What's the best way to convert a List of Lists in scala (2.9)? I have a list: List[List[A]] which I want to convert into List[A] How can that be achieved recursively? Or is there any other better way? List has the flatten method. Why not use it? List(List(1,2), List(3,4)).flatten > List(1,2,3,4) Given the above example, I'm not sure you need recursion. Looks like you want List.flatten instead. e.g. scala> List(1,2,3) res0: List[Int] = List(1, 2, 3) scala> List(4,5,6) res1: List[Int] = List(4, 5, 6) scala> List(res0,res1) res2: List[List[Int]] = List(List(1, 2, 3), List(4, 5, 6)) scala> res2