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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:41:29+00:00 2026-06-17T14:41:29+00:00

So the below Python code gets the error: TypeError: ‘NoneType’ object has no attribute

  • 0

So the below Python code gets the error: TypeError: ‘NoneType’ object has no attribute ‘getitem‘

I can’t figure out why the list ‘path1‘ doesn’t get recognized as a list, but instead is recognized as NoneType.

I’ve checked previous Stack questions, googled, all of that, but I can’t figure out why it is happening. This came close-ish (I think) but I can’t tell why my state = path[-1] call is turning up this error.

Any thoughts? Much appreciated.

Thanks

Code:

import re
import string



gr = {
    "A":["B","C","D"],
    "B":["A","E"],
    "C":["A","E"],
    "D":["A","H","I","J"],
    "E":["B","C","F","G","H"],
    "F":["E"],
    "G":["E","H"],
    "H":["D","E","G","K"],
    "I":["D","K","L"],
    "J":["D","M"],
    "K":["I","M","H"],
    "L":["I"],
    "M":["K","J"]
    }

def graphSearch(graph, start, dest):
    frontier = [[start]]
    explored = []
    options = []
    if frontier == []: return "I hope you enjoyed riding aboard the failboat"
    while len(frontier)>0:
        path = frontier.pop()
        state = path[-1]
        if state == dest: 
            return path
        else:
            for a in graph[state]:
                if a not in path:
                    newP = path.append(a)
                    frontier.append(newP)
    return options



print graphSearch(gr, "A", "M")
  • 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-17T14:41:30+00:00Added an answer on June 17, 2026 at 2:41 pm
    newP = path.append(a)
    frontier.append(newP)
    

    append doesn’t return anything (it modifies the original list in place), so you wind up appending a bunch of None to your list.

    .pop() works fine; it’s the state = path[1] that fails, because the pop() popped off one of the None items you appended in a previous iteration.

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

Sidebar

Related Questions

Can anybody figure out how the python code below works and give me a
I want to determine which attribute to look-up dynamicaly, Consider below python code: def
I have a python psp page code is shown below. Currently it only prints
In the code shown below, I need to manipulate the time var in python
I am trying to implement this package http://code.google.com/p/python-progressbar/ when downloading a file like below:
Try the code below with: python fork.py and with: python fork.py 1 to see
I have been trying to debug the below python cgi code but doesn't seems
In the below python code var=input(Enter a number between 1 to 10:) if (var==1
Please go through the python code snippet below import subprocess child = subprocess.Popen(python ./myprog.py
Below is python code that attempts to find the sum of all values divided

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.