suffix

List with duplicated values and suffix

痞子三分冷 提交于 2019-12-17 07:20:32
问题 I have a list, a : a = ['a','b','c'] and need to duplicate some values with the suffix _ind added this way (order is important): ['a', 'a_ind', 'b', 'b_ind', 'c', 'c_ind'] I tried: b = [[x, x + '_ind'] for x in a] c = [item for sublist in b for item in sublist] print (c) ['a', 'a_ind', 'b', 'b_ind', 'c', 'c_ind'] I think my solution is a bit over-complicated. Is there some better, more pythonic solution? 回答1: You could make it a generator: def mygen(lst): for item in lst: yield item yield

VBA: Add Suffix to Duplicate Value within Column

落花浮王杯 提交于 2019-12-14 03:08:46
问题 I hope you can help me resolving an issue in VBA with regard to adding a suffix to duplicate values. I have a range that looks like the following: COL A: 000049 000050 000051 000052 (duplicate) 000052 (duplicate) 000053 000054 What I want to achieve is that once there is a duplicate in Column A, it adds a suffix to both numbers. I've only managed (using a loop) to set it for one of the fields. Conditions: If there is a duplicate, all duplicates must have a suffix; If there is a new duplicate

Code that creates variables, and increments its suffix [duplicate]

自作多情 提交于 2019-12-13 03:42:20
问题 This question already has answers here : How do I create a variable number of variables? (13 answers) Closed 23 days ago . My first post on Python language as I am learning it. I have a shape file that has around 10000 polygons. I am trying to generate code like below that creates Polygon1, Polygon2 all the way to Polygon10000 using syntax like this: polygon1 = shape(shapes[0]) polygon2 = shape(shapes[1]) polygon3 = shape(shapes[2]) polygon4 = shape(shapes[3]) . . polygon10000 = shape(shapes

How does extglob work with shell parameter expansion?

放肆的年华 提交于 2019-12-12 17:26:20
问题 I thought I understood the use of the optional ?(pattern-list) in bash (when extglob shell option is on) and by default in ksh. For example in bash : $ shopt -s extglob $ V=35xAB $ echo "${V#?(35|88)x}" "${V#35}" AB xAB But when the matching prefix pattern is just one ?() or one *() , which introduce what I call optional patterns , the 35 is not omitted unless ## is used: $ echo "${V#?(35|88)}" "${V#*(35|88)}" # Why 35 is not left out? 35xA 35xA $ echo "${V##?(35|88)}" "${V##*(35|88)}" # Why

How to I get the first or last few characters of a string in a method chain?

一曲冷凌霜 提交于 2019-12-12 04:01:36
问题 If I use functional-style method chains for string manipulation, I can not use the usual machinery for getting the first or last few characters: I do not have access to a reference to the current string, so I can not compute indices. Example: [some, nasty, objects] .map( { $0.asHex } ) .joined() .<first 100> .uppercased() + "..." for a truncated debug output. So how to I implement <first 100> , or do I have to break the chain? 回答1: I don't know of any API that does this. Fortunately, writing

Increment image name if already exists

走远了吗. 提交于 2019-12-11 09:51:19
问题 I'm using following code format to change image name if it already exists on server. I want incremental image names if they already exist with the same name. Ex: abc.png , abc_1.png , abc_2.png function file_newname($path, $filename){ if ($pos = strrpos($filename, '.')) { $name = substr($filename, 0, $pos); $ext = substr($filename, $pos); } else { $name = $filename; } $newpath = $path.'/'.$filename; $newname = $filename; $counter = 1; while (file_exists($newpath)) { $newname = $name .'_'.

What does the integer suffix J mean?

喜欢而已 提交于 2019-11-30 16:46:23
I have the following source: int main() { 000J; } With gcc 4.8.4 it compiles without errors. I know there are suffixes like L or U, but I didn't find anything about J. So what does it do? I get a warning: Imaginary constants are a GNU extension The J suffix is a GNU extension, which causes the literal to be of a _Complex type. More info here: https://gcc.gnu.org/onlinedocs/gcc/Complex.html As zenith mentioned, this is a GNU extension for writing imaginary literals. I really want to comment on the rationale of using j for this purpose as imallett is wondering but I don't have enough reputation

What does the integer suffix J mean?

狂风中的少年 提交于 2019-11-30 00:04:17
问题 I have the following source: int main() { 000J; } With gcc 4.8.4 it compiles without errors. I know there are suffixes like L or U, but I didn't find anything about J. So what does it do? 回答1: I get a warning: Imaginary constants are a GNU extension The J suffix is a GNU extension, which causes the literal to be of a _Complex type. More info here: https://gcc.gnu.org/onlinedocs/gcc/Complex.html 回答2: As zenith mentioned, this is a GNU extension for writing imaginary literals. I really want to

Add a text suffix to <input type=“number”>

倾然丶 夕夏残阳落幕 提交于 2019-11-29 04:19:08
I currently have a number of inputs like this: <input type="number" id="milliseconds"> This input field is used to represent a value in milliseconds. I do however have multiple number inputs which take a value in dB or percentages. <input type="number" id="decibel"> <input type="number" id="percentages"> What I would like to do is add a type suffix to the input field to let users know what kind of value the input represents. Something like this: (This image is edited to show what result I want to have,I hid the up and down arrows from the input type as well). I have tried to Google this but I

List with duplicated values and suffix

我们两清 提交于 2019-11-27 07:34:02
I have a list, a : a = ['a','b','c'] and need to duplicate some values with the suffix _ind added this way (order is important): ['a', 'a_ind', 'b', 'b_ind', 'c', 'c_ind'] I tried: b = [[x, x + '_ind'] for x in a] c = [item for sublist in b for item in sublist] print (c) ['a', 'a_ind', 'b', 'b_ind', 'c', 'c_ind'] I think my solution is a bit over-complicated. Is there some better, more pythonic solution? MSeifert You could make it a generator: def mygen(lst): for item in lst: yield item yield item + '_ind' >>> a = ['a','b','c'] >>> list(mygen(a)) ['a', 'a_ind', 'b', 'b_ind', 'c', 'c_ind'] You