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

  • Home
  • SEARCH
  • 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 7402253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:41:54+00:00 2026-05-29T04:41:54+00:00

str = ” for i in self.obj: str += ‘[‘ + self.obj[i] + ‘]’;

  • 0
str = ''

for i in self.obj:
    str += '[' + self.obj[i] + ']';

Is there a way to simplify the code?

  • 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-05-29T04:41:55+00:00Added an answer on May 29, 2026 at 4:41 am

    Assuming that self.obj is a dict:

    string = ''.join('[%s]' % x for x in self.obj.itervalues())
    

    If it’s a custom object implementing __getitem__ instead:

    string = ''.join('[%s]' % self.obj[x] for x in self.obj)
    

    Note that I don’t use str as a variable name. You shouldn’t do this as well, because it’s a builtin function in Python.

    UPDATE: Regarding your last comment, you could do something like this:

    string = ''.join('[%s%s]' % (x[1:], self.obj[x]) for x in self.obj)
    

    Or if you prefer the (more Pythonic?) format method:

    string = ''.join('[{0}{1}]'.format(x[1:], self.obj[x]) for x in self.obj)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have got an NSString *str = @12345.6789 and want to find out if there
Code: str = '<br><br />A<br />B' print(re.sub(r'<br.*?>\w$', '', str)) It is expected to return
NSString *str = [[NSString alloc]init]; str = [str initWithString:@]; This code crashes. If I
var str = 'internet'; performAction(function(str) { console.log(str); }); Is there a problem with having
str := new(bytes.Buffer) //old code printer.Fprint(str, c) //old code str := new(token.FileSet) //new code
str(file.key) = '1011/101011/file_name' newFileName = str(file.key) But, when I run the code i get:
str_replace('Ê','',$line); Ain't working. Is there some special string that represents that?
string str = one three; string::iterator it; string add = two ; Lets say
When compiling this: char *str = [[NSString stringWithFormat:@%i days and %i hours, days, hours]
function escCtrlChars(str) { return str.replace(/[\0\t\n\v\f\r\xa0'!-]/g, function(c) { return '!' + c.charCodeAt(0) + '!'; });

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.