concatenation

String Manipulation insert a character every 4th character [duplicate]

北城以北 提交于 2020-08-10 19:01:12
问题 This question already has answers here : Putting char into a java string for each N characters (11 answers) Closed 4 years ago . In Android if I have an edit text and the user entered 123456789012, how could I get the program to insert a dash every 4th character. ie: 1234-5678-9012 ? I guess you need to say something along the lines of:- a=Characters 1~4, b=Characters 5~8, c=Characters 9-12 , Result = a + "-" + b + "-" + c . But I am unsure of how that would look in Android. Many thanks for

How to concatenate huge number of files

痴心易碎 提交于 2020-08-02 07:11:23
问题 I would like to concatenate my files. I use cat *txt > newFile But I have almost 500000 files and it complains that the argument list is too long. Is there an efficient and fast way of merging half a million files? Thanks 回答1: If your directory structure is shallow (there are no subdirectories) then you can simply do: find . -type f -exec cat {} \; > newFile If you have subdirectories, you can limit the find to the top level, or you might consider putting some of the files in the sub

how to collapse columns in pandas on null values?

点点圈 提交于 2020-07-29 17:16:32
问题 Suppose I have the following dataframe: pd.DataFrame({'col1': ["a", "a", np.nan, np.nan, np.nan], 'override1': ["b", np.nan, "b", np.nan, np.nan], 'override2': ["c", np.nan, np.nan, "c", np.nan]}) col1 override1 override2 0 a b c 1 a NaN NaN 2 NaN b NaN 3 NaN NaN c 4 NaN NaN NaN Is there a way to collapse the 3 columns into one column, where override2 overrides override1 , which overrides col1 , however, in case there is NaN, then the values bofore is to be kept? Also, I am mainly looking for

how to collapse columns in pandas on null values?

99封情书 提交于 2020-07-29 17:15:35
问题 Suppose I have the following dataframe: pd.DataFrame({'col1': ["a", "a", np.nan, np.nan, np.nan], 'override1': ["b", np.nan, "b", np.nan, np.nan], 'override2': ["c", np.nan, np.nan, "c", np.nan]}) col1 override1 override2 0 a b c 1 a NaN NaN 2 NaN b NaN 3 NaN NaN c 4 NaN NaN NaN Is there a way to collapse the 3 columns into one column, where override2 overrides override1 , which overrides col1 , however, in case there is NaN, then the values bofore is to be kept? Also, I am mainly looking for

Flattening a multilevel list of lists to a single level

一世执手 提交于 2020-07-20 04:58:12
问题 I need to flatten all the levels of a multi-level list: import itertools pool = [[[[[0,2],[1,3]],[[3,2],[1,0]]],"PdPd","PrisonerDilemma"], [[[[0,3],[1,2]],[[2,3],[1,0]]],"ShSh","StagHunt"], [[[[1,2],[3,0]],[[3,2],[1,0]]],"ChCh","Chicken"], [[[[2,1],[0,3]],[[3,1],[0,2]]],"BaBa","Battle"]] def flat3 (pool): for game in pool: l = list(itertools.chain.from_iterable(game[0])) print(l) The result: flat3 (pool) [[0, 2], [1, 3], [3, 2], [1, 0]] [[0, 3], [1, 2], [2, 3], [1, 0]] [[1, 2], [3, 0], [3, 2]

Flattening a multilevel list of lists to a single level

依然范特西╮ 提交于 2020-07-20 04:56:07
问题 I need to flatten all the levels of a multi-level list: import itertools pool = [[[[[0,2],[1,3]],[[3,2],[1,0]]],"PdPd","PrisonerDilemma"], [[[[0,3],[1,2]],[[2,3],[1,0]]],"ShSh","StagHunt"], [[[[1,2],[3,0]],[[3,2],[1,0]]],"ChCh","Chicken"], [[[[2,1],[0,3]],[[3,1],[0,2]]],"BaBa","Battle"]] def flat3 (pool): for game in pool: l = list(itertools.chain.from_iterable(game[0])) print(l) The result: flat3 (pool) [[0, 2], [1, 3], [3, 2], [1, 0]] [[0, 3], [1, 2], [2, 3], [1, 0]] [[1, 2], [3, 0], [3, 2]

Flattening a multilevel list of lists to a single level

断了今生、忘了曾经 提交于 2020-07-20 04:55:23
问题 I need to flatten all the levels of a multi-level list: import itertools pool = [[[[[0,2],[1,3]],[[3,2],[1,0]]],"PdPd","PrisonerDilemma"], [[[[0,3],[1,2]],[[2,3],[1,0]]],"ShSh","StagHunt"], [[[[1,2],[3,0]],[[3,2],[1,0]]],"ChCh","Chicken"], [[[[2,1],[0,3]],[[3,1],[0,2]]],"BaBa","Battle"]] def flat3 (pool): for game in pool: l = list(itertools.chain.from_iterable(game[0])) print(l) The result: flat3 (pool) [[0, 2], [1, 3], [3, 2], [1, 0]] [[0, 3], [1, 2], [2, 3], [1, 0]] [[1, 2], [3, 0], [3, 2]