string-concatenation

Concatenate string to the end of all elements of a list in python

拈花ヽ惹草 提交于 2021-01-27 14:23:45
问题 I would like to know how to concatenate a string to the end of all elements in a list. For example: List1 = [ 1 , 2 , 3 ] string = "a" output = ['1a' , '2a' , '3a'] 回答1: rebuild the list in a list comprehension and use str.format on both parameters >>> string="a" >>> List1 = [ 1 , 2 , 3 ] >>> output = ["{}{}".format(i,string) for i in List1] >>> output ['1a', '2a', '3a'] 回答2: In one line: >>> lst = [1 , 2 , 3] >>> my_string = 'a' >>> [str(x) + my_string for x in lst] ['1a', '2a', '3a'] You

Concatenate inputs in string while in loop

老子叫甜甜 提交于 2021-01-27 02:55:00
问题 I have a variable of sources that is basically a string of comma-separated elements: SOURCES="a b c d e" I want the user to input one destination for each of this source, and I want hence to store this input into a string looking like the above but containing the destinations. If I want to assign a=1, b=2... etc, I would have something like this: echo $DESTINATIONS >>> "1 2 3 4 5" In order to do the above, I do this: SOURCES="a b c d e" DESTINATIONS="" for src in $SOURCES do echo Input

Concatenate inputs in string while in loop

安稳与你 提交于 2021-01-27 02:54:11
问题 I have a variable of sources that is basically a string of comma-separated elements: SOURCES="a b c d e" I want the user to input one destination for each of this source, and I want hence to store this input into a string looking like the above but containing the destinations. If I want to assign a=1, b=2... etc, I would have something like this: echo $DESTINATIONS >>> "1 2 3 4 5" In order to do the above, I do this: SOURCES="a b c d e" DESTINATIONS="" for src in $SOURCES do echo Input

Concatenate char literal ('x') vs single char string literal (“x”)

不羁岁月 提交于 2021-01-20 15:31:40
问题 When I have a String that I need to concatenate a single char to its end, should I prefer s = .... + ']' over s = .... + "]" for any performance reason? I know array string joining and of String builders, and I am NOT asking for suggestions on how to concatenate strings in general. I also know some of would have the urge to explain to me about premature optimizations and that in general I should not bother with such minor stuff, please don't... I am asking because from a coding style

Concatenating two text columns in dplyr

一世执手 提交于 2020-11-27 04:59:31
问题 My data look like this: round <- c(rep("A", 3), rep("B", 3)) experiment <- rep(c("V1", "V2", "V3"), 2) results <- rnorm(mean = 10, n = 6) df <- data.frame(round, experiment, results) > df round experiment results 1 A V1 9.782025 2 A V2 8.973996 3 A V3 9.271109 4 B V1 9.374961 5 B V2 8.313307 6 B V3 10.837787 I have a different dataset that will be merged with this one where each combo of round and experiment is a unique row value, ie, "A_V1" . So what I really want is a variable name that

Concatenating two text columns in dplyr

痞子三分冷 提交于 2020-11-27 04:58:51
问题 My data look like this: round <- c(rep("A", 3), rep("B", 3)) experiment <- rep(c("V1", "V2", "V3"), 2) results <- rnorm(mean = 10, n = 6) df <- data.frame(round, experiment, results) > df round experiment results 1 A V1 9.782025 2 A V2 8.973996 3 A V3 9.271109 4 B V1 9.374961 5 B V2 8.313307 6 B V3 10.837787 I have a different dataset that will be merged with this one where each combo of round and experiment is a unique row value, ie, "A_V1" . So what I really want is a variable name that

MongoDB Aggregation join array of strings to single string

戏子无情 提交于 2020-08-22 04:07:32
问题 We're trying to 'join' an array of strings to a single string within an aggregation. Given is the following dataset: Collection 1: { id: 1234, field: 'test' } Collection 2: { id: 1111, collection1_id: 1234, name: 'Max' }, { id: 1112, collection1_id: 1234, name: 'Andy' } The current result (after lookup etc.): { id: 1234, field: 'test', collection2: ['Max', 'Andy'] } The desired result: { id: 1234, field: 'test', collection2: 'Max, Andy' } Is it somehow possible to join the 'collection2' to a

String Aggregation in Oracle: Multiple Rows into Single Column

不问归期 提交于 2020-07-30 10:46:30
问题 hi I have following function for string aggregation in oracle CREATE OR REPLACE FUNCTION STRING_AGGREGATE(i_query VARCHAR2, i_seperator VARCHAR2 DEFAULT ',') RETURN VARCHAR2 AS l_return CLOB:=''; l_temp VARCHAR(32000); TYPE r_cursor is REF CURSOR; rc r_cursor; BEGIN OPEN rc FOR i_query; LOOP FETCH rc INTO L_TEMP; EXIT WHEN RC%NOTFOUND; l_return:=l_return||L_TEMP||i_seperator; END LOOP; RETURN RTRIM(l_return,i_seperator); END; when i call this function it show like this SELECT STRING_AGGREGATE