I don't understand how the list
function works.
Here is the research I have done:
Documentation I am looking at:
In particular, I am looking at this paragraph:
class list([iterable]) Return a list whose items are the same and in the same order as iterable’s items. iterable may be either a sequence, a container that supports iteration, or an iterator object. If iterable is already a list, a copy is made and returned, similar to iterable[:]. For instance, list('abc') returns ['a', 'b', 'c'] and list( (1, 2, 3) ) returns [1, 2, 3]. If no argument is given, returns a new empty list, [].
list is a mutable sequence type, as documented in Sequence Types — str, unicode, list, tuple, bytearray, buffer, xrange. For other containers see the built in dict, set, and tuple classes, and the collections module.
Here is another post:
Another post about the list function
On that post, the someone posts the following:
>>> myList = ['hello']
>>> myList=list(myList[0])
>>> myList
['h', 'e', 'l', 'l', 'o']
But when I do this:
for root, dirs, files in os.walk(os.getcwd()):
path_files.append(files)
path_files
[['combinedPdfs.py', 'meetingminutes.pdf', 'meetingminutes_encrypted.pdf', 'pdf_intro.py', 'pdf_paranoia.py', 'readDocx.py']]
>>> path_files_2 = list(path_files[0])
>>> path_files_2
['combinedPdfs.py', 'meetingminutes.pdf', 'meetingminutes_encrypted.pdf', 'pdf_intro.py', 'pdf_paranoia.py', 'readDocx.py']
>>> path_files_2[0]
'combinedPdfs.py'
>>> path_files_2[1]
'meetingminutes.pdf'
Why did what I do work differently than the user from the other post?
Edit #1:
If I run something like this:
>>> myList2 = ['hello', 'goodbye']
>>> myList2[0]
'hello'
>>> myList2 = list(myList2)
>>> myList2
['hello', 'goodbye']
>>> myList2 = list(myList2[0])
>>> myList2
['h', 'e', 'l', 'l', 'o']
If I run something like this:
>>> myList4 = [['Hello', 'goodbye']]
>>> myList4 = list(myList4)
>>> myList4
[['Hello', 'goodbye']]
>>> myList4 = list(myList4[0])
>>> myList4
['Hello', 'goodbye']
I see the definition, but I wish there was a more "laymans" way to explain it.