list

convert list to a particular json in python

此生再无相见时 提交于 2021-02-17 07:15:09
问题 I am working on a problem and my output is something like this: List with long string inside it ["21:15-21:30 IllegalAgrumentsException 1, 21:15-21:30 NullPointerException 2, 22:00-22:15 UserNotFoundException 1, 22:15-22:30 NullPointerException 1 ....."] I need to convert the data in something like this: response: [ { "time": "21:15-21:30", "logs": [ { "exception": "IllegalAgrumentsException", "count": 1 },{ "exception": "NullPointerException", "count": 2 } ] }, { "time": "22:00-22:15", "logs

Numpy: how to select items in numpy and assign its value

泄露秘密 提交于 2021-02-17 07:10:12
问题 I have got a problem in assigning new value by list. I want to change 12 items values in s numpy by numpy array's index ,and i hope every index i choose is different. so i made a list random.sample(range(0,len(s),12) to select 12 different index.And through this index change some of values in numpy array s() However, I'm getting the error: SyntaxError: can't assign to function call import numpy as np import random N = 20 s = np.zeros([N]) alist = random.sample(range(0,20),12) alist for i in

Simultaneously merge multiple data.frames in a list

微笑、不失礼 提交于 2021-02-17 07:04:54
问题 I have a list of many data.frames that I want to merge. The issue here is that each data.frame differs in terms of the number of rows and columns, but they all share the key variables (which I've called "var1" and "var2" in the code below). If the data.frames were identical in terms of columns, I could merely rbind , for which plyr's rbind.fill would do the job, but that's not the case with these data. Because the merge command only works on 2 data.frames, I turned to the Internet for ideas.

Simultaneously merge multiple data.frames in a list

假如想象 提交于 2021-02-17 07:04:31
问题 I have a list of many data.frames that I want to merge. The issue here is that each data.frame differs in terms of the number of rows and columns, but they all share the key variables (which I've called "var1" and "var2" in the code below). If the data.frames were identical in terms of columns, I could merely rbind , for which plyr's rbind.fill would do the job, but that's not the case with these data. Because the merge command only works on 2 data.frames, I turned to the Internet for ideas.

Generating nested lists from XML doc

独自空忆成欢 提交于 2021-02-17 06:41:27
问题 Working in python, my goal is to parse through an XML doc I made and create a nested list of lists in order to access them later and parse the feeds. The XML doc resembles the following snippet: <?xml version="1.0'> <sources> <!--Source List by Institution--> <sourceList source="cbc"> <f>http://rss.cbc.ca/lineup/topstories.xml</f> </sourceList> <sourceList source="bbc"> <f>http://feeds.bbci.co.uk/news/rss.xml</f> <f>http://feeds.bbci.co.uk/news/world/rss.xml</f> <f>http://feeds.bbci.co.uk

Get unique elements from a 2D list

你离开我真会死。 提交于 2021-02-17 06:32:18
问题 I have a 2D list which I create like so: Z1 = [[0 for x in range(3)] for y in range(4)] I then proceed to populate this list, such that Z1 looks like this: [[1, 2, 3], [4, 5, 6], [2, 3, 1], [2, 5, 1]] I need to extract the unique 1x3 elements of Z1 , without regard to order: Z2 = makeUnique(Z1) # The solution The contents of Z2 should look like this: [[4, 5, 6], [2, 5, 1]] As you can see, I consider [1, 2, 3] and [2, 3, 1] to be duplicates because I don't care about the order. Also note that

List all guilds with multiple servers on a single embed

谁说我不能喝 提交于 2021-02-17 06:31:28
问题 This is my current code which shows the servers it is currently in. Which this does what I would like it to do, but it is not efficient and can be avoided instead of sending an embed message for each server it gets. @client.command() @commands.is_owner() async def list_guilds(ctx): servers = client.guilds for guild in servers: embed = discord.Embed(colour=0x7289DA) embed.set_footer(text=f"Guilds requested by {ctx.author}", icon_url=ctx.author.avatar_url) embed.add_field(name=(str(guild.name))

List all guilds with multiple servers on a single embed

最后都变了- 提交于 2021-02-17 06:31:08
问题 This is my current code which shows the servers it is currently in. Which this does what I would like it to do, but it is not efficient and can be avoided instead of sending an embed message for each server it gets. @client.command() @commands.is_owner() async def list_guilds(ctx): servers = client.guilds for guild in servers: embed = discord.Embed(colour=0x7289DA) embed.set_footer(text=f"Guilds requested by {ctx.author}", icon_url=ctx.author.avatar_url) embed.add_field(name=(str(guild.name))

Fastest Proxy Iteration in Python

僤鯓⒐⒋嵵緔 提交于 2021-02-17 06:10:45
问题 Let's say I have a list that contains 10,000+ proxies proxy_list = ['ip:port','ip:port',.....10,000+ items] How do I iterate it to get the proxies that works for my pc? Using the following code it is possible to find it , but takes 5*10,000 seconds to get completed. How would I iterate through the list faster? import requests result=[] for I in proxy_list: try: requests.get('http:\\www.httpbin.org\ip',proxies = {'https' : I, 'http' : I } ,timeout = 5) result.append(I) except: pass 回答1: You

Fastest Proxy Iteration in Python

随声附和 提交于 2021-02-17 06:10:29
问题 Let's say I have a list that contains 10,000+ proxies proxy_list = ['ip:port','ip:port',.....10,000+ items] How do I iterate it to get the proxies that works for my pc? Using the following code it is possible to find it , but takes 5*10,000 seconds to get completed. How would I iterate through the list faster? import requests result=[] for I in proxy_list: try: requests.get('http:\\www.httpbin.org\ip',proxies = {'https' : I, 'http' : I } ,timeout = 5) result.append(I) except: pass 回答1: You