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 9023277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:43:25+00:00 2026-06-16T05:43:25+00:00

I am getting myself all tangled up where in the nesting. I have a

  • 0

I am getting myself all tangled up where in the nesting.

I have a list of python objects that look like this:

notes = [
     {'id':1,
      'title':'title1',
      'text':'bla1 bla1 bla1',
      'tags':['tag1a', ' tag1b', ' tag1c']},
     {'id':2,
      'title':'title2',
      'text':'bla2 bla2 bla2',
      'tags':[' tag2a', ' tag2b', ' tag2c']},
     {'id':3,
      'title':'title3',
      'text':'bla3 bla3 bla3',
      'tags':[' tag3a', ' tag3b', ' tag3c']}] 

and so on.

I am trying to go into each dictionary in the list and strip out the left whitespaces and return a list of dictionaries where the only difference are the tags have their uneccessary white space stripped.

The following code is what I am working with, but it is not right and I don’t know what I am doing to get to the result i need.

notes_cleaned = []
for objs in notes:
    for items in objs:
        notes_cleaned.append({'text':n['text'], 'id':n['id'], 'tags':[z.lstrip(' ') for z in n['tags']], 'title':n['title']})

Which gives me an error that i can’t use string indexes, which I understand, but I don’t know how to do it right. since I know that I have to iterate over each dictionary like:

for objs in notes:
    for items in objs:
        print items, objs[items]

but I am confused as to how to get to the final part of rebuilding the dictionaries while digging into the tag lists specifically.

What am I missing here (knowing that I am definitely missing something).

  • 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-16T05:43:27+00:00Added an answer on June 16, 2026 at 5:43 am

    The following code should work, assuming only “tags” needs to be stripped:

    def clean(items):
        clean = []
        for objs in items:
            nObj = {}
            for item, obj in objs.iteritems():
                if item != "tags":
                    nObj[item] = obj
                else:
                    nObj["tags"] = [n.lstrip() for n in obj]
            clean.append(nObj)
        return clean
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting myself confused with all these languages! :) // given this function var
I am getting myself a bit confused about how to go about this. My
Getting red warning message that expected identifier for this statement CALayer = ImageView.layer; Using
So I'm supposed to be a .Net Developer but have found myself getting stuck
I am currently getting myself into Spring-Roo and Spring-MVC. I have a fairly simple
I have seen several similar questions to this, but none that addresses my specific
I've set myself the task of implementing a real time MIDI application. Like all
Now that I've read all the DQL docs I still have some doubts, I'm
I find myself in a situation that someone else must have got stuck in
I was so pleased with myself getting this to work last night without any

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.