A quick help on python dict


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 1 Week Ago
A quick help on python dict

Hi Team,
I'm new to python and working on a project.
I have an API call which returns a dict(got the dict.values() and converted to list) as shown below:

Code:
dict_values([OffsetAndMetadata(offset=66, metadata=''), OffsetAndMetadata(offset=107, metadata=''), OffsetAndMetadata(offset=189, metadata='')])

Any clue, how can I get only offset values, in deed I need a sum of those. I can write a "shell sed command" inside python and using os.command can get the work done, but looking for a cleaner python solution/hint.
Thanks,
Ravi
This User Gave Thanks to panyam For This Post:
vbe (1 Week Ago)
# 2  
Old 1 Week Ago
Hi,

Managed to find a solution within python. Can be closed.

Code:
for item in dict.values():
            currentOffset+=int(str(item).partition("offset")[2].partition("metadata")[0].replace('=','').replace(',',''))

thnx
# 3  
Old 1 Week Ago
Thanks for sharing and pleased you found by yourself a suitable solution
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
How to execute python script on remote with python way..? onenessboy Windows & DOS: Issues & Discussions 1 12-14-2018 10:09 AM
**python** unable to read the background color in python giridhar276 Shell Programming and Scripting 1 08-05-2014 02:53 AM
"ssh suse-server 'python -V' > python-version.out" not redirecting Druonysus SuSE 3 02-13-2013 08:59 PM
Python: bash-shell-like less functionality in the python shell Narnie Programming 0 06-25-2010 02:11 PM
grep: can't open /usr/dict/words Rajakct84 Shell Programming and Scripting 2 11-25-2009 09:37 AM
Quick help! rags_s11 Solaris 2 11-13-2008 07:07 PM
Quick one kekanap Shell Programming and Scripting 4 01-31-2008 06:23 AM
Need quick help SanjayLinux Shell Programming and Scripting 1 09-25-2007 09:36 AM
quick question keith.m AIX 5 12-21-2006 08:27 AM
Quick question JohnnyBoy UNIX for Dummies Questions & Answers 2 11-03-2006 07:23 AM
quick question pkolishetty UNIX for Dummies Questions & Answers 2 09-02-2006 11:56 AM
i need quick help???...please M_Hafez UNIX for Dummies Questions & Answers 3 01-14-2005 06:22 AM