listname[0][0] What does the second bracket represent?

This is the place for queries that don't fit in any of the other categories.

listname[0][0] What does the second bracket represent?

Postby Shirtless » Fri Aug 01, 2014 11:04 pm

super newb here, stumbled upon a solution but i'm not actually sure what it means. i'm trying to encode elements of a truple, but varlist[0].encode wasn't working. i poked around online and tried varlist[0][0].encode and that worked. but i don't even know what that second bracket represents. can someone help? :)
Last edited by micseydel on Fri Aug 01, 2014 11:31 pm, edited 1 time in total.
Reason: First post lock.
Shirtless
 
Posts: 2
Joined: Fri Aug 01, 2014 10:59 pm

Re: listname[0][0] What does the second bracket represent?

Postby micseydel » Fri Aug 01, 2014 11:41 pm

Welcome to the forum! You might want to introduce yourself here (though it's not mandatory) and read this to learn how to make better posts (maybe not "mandatory" but strongly recommended).

If you give us a runnable code snippet less than 20 lines, we can give you a better answer, but in general what I can say is that if you use brackets twice, that you have a collection inside of a collection (like a matrix, if you're familiar with those from math; no worries if not). The first bracket accesses the inner collection, and the second bracket accesses the item inside that collection. A string can be thought of as a collection of characters, so if you had a list of strings you could access the third character of the second string with
Code: Select all
strings[1][2]

If this seems unclear, feel free to post code closer to what you already have and we can adapt an example to that.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1355
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: listname[0][0] What does the second bracket represent?

Postby Shirtless » Sat Aug 02, 2014 12:18 am

micseydel wrote:Welcome to the forum! You might want to introduce yourself here (though it's not mandatory) and read this to learn how to make better posts (maybe not "mandatory" but strongly recommended).

If you give us a runnable code snippet less than 20 lines, we can give you a better answer, but in general what I can say is that if you use brackets twice, that you have a collection inside of a collection (like a matrix, if you're familiar with those from math; no worries if not). The first bracket accesses the inner collection, and the second bracket accesses the item inside that collection. A string can be thought of as a collection of characters, so if you had a list of strings you could access the third character of the second string with
Code: Select all
strings[1][2]

If this seems unclear, feel free to post code closer to what you already have and we can adapt an example to that.


Hello,

Thank you for the response and the links. Will definitely look into those.

You're absolutely right that's what I had. I collected information that automatically pulled into a list, and then I manually appended them into another list.

Best,
Richard
Shirtless
 
Posts: 2
Joined: Fri Aug 01, 2014 10:59 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests