Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8091401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:03:27+00:00 2026-06-05T20:03:27+00:00

I have a dictionary, user_dict, and create a list for each user value, this

  • 0

I have a dictionary, user_dict, and create a list for each user value, this list contains json object:

user_dict[user].append(obj)

Now I want to print all the items in this dictionary, but only select some field from each item in the list, so the dictionary is like this, I only list one user here

{u'user1':[{u'host_dst': {u'addr': u'195.149.144.60', u'vid': 0, u'port': 80},

            'usi': '7932fee11ba72ae84180044d75521368', u'host_src': {u'addr': u'83.233.59.215', 

            u'vid': 0, u'port': 51068},item2...]}

What I did is:

for item in user_dict.values():
    fd_out1.write("%s\t%s\n" % (item["host_dst"][addr],item["host_dst"]["vid"]))

and it returns:

TypeError: list indices must be integers, not str

Previously for example, I used obj[“host_dst”][addr] to represent the value 195.149.144.60, and it works fine, but here when I want to print out something, it cannot work. Can anyone help? Many thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:03:28+00:00Added an answer on June 5, 2026 at 8:03 pm

    you missed a bracket in your post

    after proper formatting, your data looks like this

    {
      u'user1': [
                    {
                      u'host_dst': {
                                      u'addr': u'195.149.144.60',
                                      u'vid': 0,
                                      u'port': 80
                                   },
    
                      'usi': '7932fee11ba72ae84180044d75521368',
                      u'host_src': {
                                      u'addr': u'83.233.59.215', 
                                      u'vid': 0, 
                                      u'port': 51068
                                    }
                     },
                    item2,
                    ...
               ]
    }
    

    so each item in your loop is a list

    you should print out something like item[0]["host_dst"][addr]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an info dictionary that contains user data. Currently, it is written to
I have a dictionary like this: user_dict = { user1: [(video1, 10), (video2, 20),
I would like to have a dictionary object contains string keys and values, which
I have a dictionary of strings that i want the user to be able
I have a website that holds a dictionary of data sets. When a user
Does VBA have dictionary structure? Like key<>value array?
I have a Dictionary called AvailableBoxes. I want to lookup a string in this
I have this dictionary in my apps model file: TYPE_DICT = ( (1, Shopping
I have used AutoCompleteBox usercontrol. I have a dictionary of type Dictionary<int,string> which contains
I have a list like this: [(ip1, video1, 12345.00000),(ip1, video1, 12346.12362),(ip1, video1, 12347.12684),(ip1, video2,12367.12567),(ip2,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.