Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: Json filter is not capturing desired key/element
Post: Json filter is not capturing desired key/element

Hello, I am trying to do the following: 1) Read the Json file (sample output attached). 2) If account ID is 4254254 AND "compliance": "Fail", I need to print the respective dictionary. This is what ...
mrapple2020 General Coding Help 1 1,124 Nov-23-2022, 10:26 PM
    Thread: Read nested data from JSON - Getting an error
Post: RE: Read nested data from JSON - Getting an error

Thank you for your professionalism. My bad. I ran the code below and it executes. Can you do me a favor and point out from here how can I retrieve the value of the "compliance" key? import json de...
mrapple2020 General Coding Help 5 1,358 Nov-23-2022, 02:31 AM
    Thread: Any suggestions to improve BuySell stock problem efficiency?
Post: Any suggestions to improve BuySell stock problem e...

I resolved the problem below. It seems this is (O(n)) = n^2. In case you have a more efficient way to resolve it, kindly let me know. Thanks. #########################################################...
mrapple2020 General Coding Help 0 1,365 May-13-2020, 06:19 PM
    Thread: Best section to do a while loop in my code
Post: Best section to do a while loop in my code

Hello, this is my goal: User will enter password thru a function getpass(). That function to get password will occur just one time. Then a list of IP addresses should be retrieved from a .txt file. Th...
mrapple2020 General Coding Help 0 1,646 Apr-15-2019, 01:14 AM
    Thread: How to list number of times element is in defaultdict and delete it
Post: RE: How to list number of times element is in defa...

Here. I am getting an error when I try. https://docs.python.org/2/library/collec...efaultdict Setting the default_factory to int makes the defaultdict useful for counting (like a bag or multiset in ...
mrapple2020 General Coding Help 3 2,672 Apr-14-2019, 10:46 PM
    Thread: How to list number of times element is in defaultdict and delete it
Post: How to list number of times element is in defaultd...

Goal: if I see a certain value (example below is "0/1") listed more than 2 or more times I want: 1) Remove all respective items from the defaultdict value list. I tried the example below from the do...
mrapple2020 General Coding Help 3 2,672 Apr-14-2019, 10:09 PM
    Thread: Regex to extract IPs between () not working
Post: RE: Regex to extract IPs between () not working

It improved. At least I get match. But any idea why I am getting only incomplete like below? I try on rubular.com and it appears to work. But when I apply it to my text it is different: >>> &...
mrapple2020 General Coding Help 5 3,430 Apr-12-2019, 02:36 AM
    Thread: Regex to extract IPs between () not working
Post: RE: Regex to extract IPs between () not working

To be more precise, I am puzzled why the below doesn't match (50.50.50.22,230.207.200.20). Any ideas? s = """ rate 230.207.200.1', '', ' (50.50.50.11,230.207.200.1)', ' Incoming rate : 1013 / ...
mrapple2020 General Coding Help 5 3,430 Apr-12-2019, 01:23 AM
    Thread: Regex to extract IPs between () not working
Post: Regex to extract IPs between () not working

Hello, can you please help me retrieve IP addresses between (). Like this: (1.1.1.1,230.1.1.1) Notice the below is not working since it is capturing text like this: match=re.findall(r'\(([0-9].+)\),st...
mrapple2020 General Coding Help 5 3,430 Apr-12-2019, 12:03 AM
    Thread: Getting list inside of a list; how to clean it and retrieve value
Post: RE: Getting list inside of a list; how to clean it...

Sorry if I still didn't get it. Let's say if I need to list the items I highlighted below (they are always the zz[variable][1]. If possible, can you kindly tell me your way to get a for loop and itera...
mrapple2020 General Coding Help 5 2,940 Apr-09-2019, 11:51 PM
    Thread: Getting list inside of a list; how to clean it and retrieve value
Post: RE: Getting list inside of a list; how to clean it...

So if I want to list values 1, 2, 3, 4, 5, I did: 'NODE': [[['1013'], ['1'], ['5/6']], [['1013'], ['2'], ['0/6']], [['1013'], ['3'], ['0/9']], [['1013'], ['4'], ['0/1']], [['1013'], ['5'], ['5/6']], [...
mrapple2020 General Coding Help 5 2,940 Apr-09-2019, 09:53 PM
    Thread: Getting list inside of a list; how to clean it and retrieve value
Post: Getting list inside of a list; how to clean it and...

When I print output from a dictionary, I get the following output as shown under "NOW LISTING". to be honest I cannot understand at what point the data got these multiple [[[. It seems a list inside ...
mrapple2020 General Coding Help 5 2,940 Apr-09-2019, 08:26 PM
    Thread: Error 'object has no attribute' when iterating thru a dictionary
Post: RE: Error 'object has no attribute' when iterating...

Now I am getting index = [0]. I did: for k, v in arch_dic.items(): match = str(match) match = match.strip("[]") match =...
mrapple2020 General Coding Help 8 6,950 Apr-08-2019, 01:36 AM
    Thread: Error 'object has no attribute' when iterating thru a dictionary
Post: RE: Error 'object has no attribute' when iterating...

Wait a minute. If I do: #Interface variable match: match='0/7' Then I execute it and I get a match. So it seems the issue is that [] character still on the interface "match" variable. But when I co...
mrapple2020 General Coding Help 8 6,950 Apr-07-2019, 11:31 PM
    Thread: Error 'object has no attribute' when iterating thru a dictionary
Post: RE: Error 'object has no attribute' when iterating...

I executed your suggestion below (removed if match). Then I got this error: print([index for index, value in enumerate(v) if match in value]) TypeError: 'in <string>' requires string as left...
mrapple2020 General Coding Help 8 6,950 Apr-07-2019, 11:10 PM
    Thread: Error 'object has no attribute' when iterating thru a dictionary
Post: RE: Error 'object has no attribute' when iterating...

Update: if I do match = '0/7/CPU0' #match is the 'interface' variable. Then I get a match now. Ding. Maybe I need to extract the /CPU0 info from the list of CPU value.... Output: Interface:0/7/CP...
mrapple2020 General Coding Help 8 6,950 Apr-07-2019, 09:52 PM
    Thread: Error 'object has no attribute' when iterating thru a dictionary
Post: Error 'object has no attribute' when iterating thr...

from collections import defaultdict arch_dic = {} arch_dic = defaultdict(list) arch_dic['PSE2'].append("0/7/CPU0") arch_dic['PSE2'].append("1/7/CPU0") interface=['0/7'] for k, v in arch_dic.items(): ...
mrapple2020 General Coding Help 8 6,950 Apr-07-2019, 06:25 PM
    Thread: I converted string to 'list', but it doesn't look like a list!
Post: RE: I converted string to 'list', but it doesn't l...

Thank you. the split ('\n') was enough. Appreciated.
mrapple2020 General Coding Help 3 3,242 Apr-07-2019, 02:34 PM
    Thread: I converted string to 'list', but it doesn't look like a list!
Post: I converted string to 'list', but it doesn't look ...

Goal: If I find "FP-X" in the string below, I need to retrieve the string on the left of "FP-X" label. Like retrieve in this example "0/1/CPU0", "0/5/CPU0" and "5/6/CPU0". I attempted to convert this ...
mrapple2020 General Coding Help 3 3,242 Apr-07-2019, 03:02 AM
    Thread: Help with regex please
Post: RE: Help with regex please

I think I found it. Here it is: raw_int_data = olist_data[1].split('Outgoing Interface List') raw_int_out = raw_int_data[1] match = re.findall(r'(TenGig[A-Za-z0-9\/\.]+)', raw_int_out) if...
mrapple2020 General Coding Help 1 1,857 Apr-07-2019, 12:36 AM

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020