iteration

Filtering Characters from a String [duplicate]

主宰稳场 提交于 2020-05-10 14:28:13
问题 This question already has answers here : Remove specific characters from a string in Python (27 answers) Closed 6 years ago . I need to make a function that takes two strings as imnput and returns a copy of str 1 with all characters from str2 removed. First thing is to iterate over str1 with a for loop, then compare to str2, to accomplish subtraction I should create a 3rd string in which to store the output but I'm a little lost after that. def filter_string(str1, str2): str3 = str1 for

Not Iterating through all lines from a csv file python3

拜拜、爱过 提交于 2020-03-05 15:10:42
问题 I am quite new to python3 and I am sure my question is very basic. I have been looking online for some help and the closest I got came from thread Find Common Region in two CSV File in PYTHON However in my case it seems it is not iterating through everyline and stop at the first one. SO in my first csv I have 2 lines, lets say: A,1,A1 B,2,B2 now in my second csv I have a thousand lines, something like A,1,B5 A,2,A2 B,2,C6 B,3,C7 C,3,D7 C,4,D8 ...... my code is as follow: read1 = csv.reader

springboot使用jmh基准测试评估json反序列化、实体转换的性能差异

╄→尐↘猪︶ㄣ 提交于 2020-03-04 13:02:49
1、背景 笔者经常把一些经常使用的数据放到redis缓存,方便程序进行读取。 比如按照不同的键名将数值存储到hash值类型中。示例如下 hash hashkey hashValue snapshot 999 "{\"id\":999,\"distId\":999,\"distName\":\"玄武区\",\"confirm\":7,\"suspect\":0,\"dead\":0,\"heal\":2,\"weight\":6.6,\"level\":\"area\",\"mapId\":\"c320100_2\",\"updateTime\":\"2020-03-03 07:20:39\"}" snapshot1 999 {"confirm":7,"dead":0,"heal":2,"weight":6.6,"mapId":"c320100_2","updateTime":"2020-03-03 07:20:39","name":"玄武区"} 以上数据分别2052条 分别将snapshot1,snapshot转换成实体,现在将对他们进行基准测试,以评测两种存储方式的性能差异 2、基准测试 2个独立进程,分别依1次热身/热加载,批量执行20次,总计40次 2.1、snapshot1相关测试 这里用的实体转换框架是 ModelMapper ,官网: http:/

number_in_month exercise (SML list iteration)

两盒软妹~` 提交于 2020-03-02 12:40:21
问题 I need to take a list of dates and a list of months and get a total count of the amount of dates that are in any of the months listed. Thus returning a single integer I had a previously defined number_in_month function which takes in a list of dates and a single month and returns the amount of dates that fall in that month. It has been tested and works correctly. I use this as the foundation for the latter function. I've traced through the number_in_months function many times and I can't seem

JMH性能测试

我与影子孤独终老i 提交于 2020-02-27 02:20:01
  JMH,即Java Microbenchmark Harness,是专门用于代码微基准测试的工具套件。何谓Micro Benchmark呢?简单的来说就是基于方法层面的基准测试,精度可以达到微秒级。当你定位到热点方法,希望进一步优化方法性能的时候,就可以使用JMH对优化的结果进行量化的分析。   JMH比较典型的应用场景有: 想准确的知道某个方法需要执行多长时间,以及执行时间和输入之间的相关性; 对比接口不同实现在给定条件下的吞吐量,找到最优实现 查看多少百分比的请求在多长时间内完成   1 、JMH环境搭建 1 <dependency> 2 <groupId>org.openjdk.jmh</groupId> 3 <artifactId>jmh-core</artifactId> 4 <version>0.7.1</version> 5 </dependency> 6 <dependency> 7 <groupId>org.openjdk.jmh</groupId> 8 <artifactId>jmh-generator-annprocess</artifactId> 9 <version>0.7.1</version> 10 <scope>provided</scope> 11 </dependency> 12 13 <plugin> 14 <groupId>org

Use variable in jq read query

≯℡__Kan透↙ 提交于 2020-02-26 02:13:05
问题 I have the following json file cat permissions.json { "foo1.bar1@email.com": [ "projects/development/roles/superadmin", "compute.networkAdmin" ], "foo2.bar2@email.co": [ "compute.networkAdmin" ] } Now I can do something like this quite well with jq $ jq -r '.["foo1.bar1@email.com"]' permissions.json [ "projects/development/roles/superadmin", "compute.networkAdmin" ] Now the email needs to come from a variable So my for loop is such that for USER in $(jq -r 'keys[]' permissions.json) do echo $

Deleting elements from numpy array with iteration

谁都会走 提交于 2020-02-25 13:32:01
问题 What is the fastest method to delete elements from numpy array while retreiving their initial positions. The following code does not return all elements that it should: list = [] for pos,i in enumerate(ARRAY): if i < some_condition: list.append(pos) #This is where the loop fails for _ in list: ARRAY = np.delete(ARRAY, _) 回答1: It really feels like you're going about this inefficiently. You should probably be using more builtin numpy capabilities -- e.g. np.where , or boolean indexing. Using np

Deleting elements from numpy array with iteration

爷,独闯天下 提交于 2020-02-25 13:26:31
问题 What is the fastest method to delete elements from numpy array while retreiving their initial positions. The following code does not return all elements that it should: list = [] for pos,i in enumerate(ARRAY): if i < some_condition: list.append(pos) #This is where the loop fails for _ in list: ARRAY = np.delete(ARRAY, _) 回答1: It really feels like you're going about this inefficiently. You should probably be using more builtin numpy capabilities -- e.g. np.where , or boolean indexing. Using np

How do I group items in an array by date?

梦想与她 提交于 2020-02-21 11:25:36
问题 Given the following array of objects: [ { "notes": "Game was played", "time": "2017-10-04T20:24:30+00:00", "sport": "hockey", "owner": "steve", "players": "10", "game_id": 1, }, { "notes": "Game was played", "time": "2017-10-04T12:35:30+00:00", "sport": "lacrosse", "owner": "steve", "players": "6", "game_id": 2, }, { "notes": "Game was played", "time": "2017-10-14T20:32:30+00:00", "sport": "hockey", "owner": "steve", "players": "4", "game_id": 3, }, { "notes": "Game was played", "time": "2017

How do I group items in an array by date?

限于喜欢 提交于 2020-02-21 11:23:22
问题 Given the following array of objects: [ { "notes": "Game was played", "time": "2017-10-04T20:24:30+00:00", "sport": "hockey", "owner": "steve", "players": "10", "game_id": 1, }, { "notes": "Game was played", "time": "2017-10-04T12:35:30+00:00", "sport": "lacrosse", "owner": "steve", "players": "6", "game_id": 2, }, { "notes": "Game was played", "time": "2017-10-14T20:32:30+00:00", "sport": "hockey", "owner": "steve", "players": "4", "game_id": 3, }, { "notes": "Game was played", "time": "2017