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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:39:46+00:00 2026-05-28T04:39:46+00:00

Easier explained with code: #test data Day1={ ‘data1’:0, ‘data2’: 1, ‘data3’: 2, ‘data4’: 3,

  • 0

Easier explained with code:

#test data
Day1={  
      'data1':0,
      'data2':   1,
      'data3':    2,
      'data4':    3,
      'data5':    4,
      'data6':    5,
      'data7':    4,
      'data8':    3,
      'data9':    2,
      'data10':    1}

Day2= {  
       'data1':    2,
       'data2':    3,
       'data3':    4,
       'data4':    5,
       'data5':    6,
       'data6':    6,
       'data7':    7,
       'data8':    6,
       'data9':    4,
       'data10':    3}

Day3= {    
       'data1':    2,
       'data2':    4,
       'data3':    5,
       'data4':    6,
       'data5':    7,
       'data6':    6,
       'data7':    8,
       'data8':    6,
       'data9':    5,
       'data10':    4}

Day4= {   
       'data1':    2,
       'data2':    4,
       'data3':    5,
       'data4':    6,
       'data5':    7,
       'data6':    6,
       'data7':    6,
       'data8':    8,
       'data9':    5,
       'data10':    4}

AllData= {'Day1':Day1,'Day2':Day2,'Day3':Day3,'Day4':Day4}


#Number of items in AllData dictionary
AllDataSize = len(AllData)
CurrentDayCounter=0

while CurrentDayCounter < AllDataSize:
    CurrentDayCounter=CurrentDayCounter+1
    CurrentDay = 'Day%s' % (CurrentDayCounter)
    #print AllData[CurrentDay]
    #add the nodes
    for day in AllData[CurrentDay]:
        print CurrentDay
        day = "%s" % (day)
        print CurrentDay[day] #does not work gives an error: TypeError: string indices must be integers, not str
        print CurrentDay[1] #works by providing a result 'a', which is the second letter in Day
        #print 'For ', CurrentDay, ' subgroup ', day,' contains ', CurrentDay[day], ' has been added to graph.'
        dayName =  "%s-%s" % (CurrentDay, Day1[day])
        #Do not create edges if its the first day
        if CurrentDay != "Day1":
            yesterday = CurrentDayCounter - 1
            print 'today is ', CurrentDayCounter, ' and yesterday is ', yesterday

When I do print CurrentDay[day] I get an error: TypeError: string indices must be integers, not str but CurrentDay[1] gives a result of a(which is the middle letter of the variable. I want to use the variable to search the dictionary as opposed to pull up a letter position.

I suspect the way, I’m doing this is totally wrong, so is there a correct way to do this?

Thanks!
p.s. sorry for the bad code, I’m just playing around with networkx, I think I removed all references to it but if I missed anything just ignore it please.

  • 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-28T04:39:47+00:00Added an answer on May 28, 2026 at 4:39 am

    That line (65) should be:

    print AllData[CurrentDay][day] 
    

    The error message occurs because print CurrentDay[day] prints the dayth character in the string CurrentDay

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

Sidebar

Related Questions

Some things are easier to implement just by hand (code), but some are easier
Is there an easier way to step through the code than to start the
This is easier to explain with some code so I'll give an example first:
I made an image to easier explain what Im after: Image Illustration http://bayimg.com/image/eabahaaci.jpg Ive
This is easier to explain with an example. Given these two classes: public class
My job would be easier, or at least less tedious if I could come
To make things easier when switching between machines (my workstation at the office and
I find it much easier to write MXML classes with embedded Script than trying
Is there an easier way to achieve the following? var obj = from row
Semantic HTML makes it easier for Google to crawl and 'understand' a website but

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.