• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What do these parenthesis inside brackets mean?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!  I'm doing a homework assignment for CS50 AI over at edx.org.  

The requirement to is fill in a single function with a pathfinding algorithym.  The data returned by that function is known as 'path.'  Almost every single line of code has an apparent meaning to me, except the syntax on this is leaving me guessing:



Path is then referred to as a multidimensional array and the intent of that code is obvious.

How does this turn path into a multidimensional array?  What data format would 'path' originally have to have been for this to make sense?  
(Let me know is you need to see more code, it's a public learning problem.)
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The part on the left of the + is a list with inside it a tuple.

I'm assuming that path already was a list, in which case a the two lists (the one with the tuple and path) are concatenated into a new list, which is then assigned to the path variable.
 
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Parenthesis delineate tuple literals.

NumPy has true multi-dimensional arrays.

The fact that a regular Python list containing (hopefully only) tuples is sort of like a multi-dimensional array (unless you add other stuff to it) is confusing to people who are used to strongly-typed statically-typed languages.

I'm just getting over this, because often if you really needed a true multi-dimensional array for some kind of computation you'd probably be using NumPy anyway.

In terms of other kinds of multi-dimensional arrays I just know out-of-the-box Python will pretty much allow you to add pretty much anything to a list.
If it should only have certain kinds of things, it is up to you to be careful in what you put into it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic