[Tutor] String within a string solution (newbie question)

Wish Dokta glenuk at gmail.com
Wed Oct 26 14:06:10 EDT 2016


Hello,

I am currently writing a basic program to calculate and display the size of
folders with a drive/directory. To do this I am storing each directory in a
dict as the key, with the value being the sum of the size of all files in
that directories (but not directories).

For example:

{ "C:\\docs" : 10, "C:\\docs123" : 200, "C:\\docs\\code\\snippets" : 5,
"C:\\docs\\code" : 20, "C:\\docs\\pics" : 200, "C:\\docs\\code\\python" :
10  }

Then to return the total size of a directory I am searching for a string in
the key:

For example:

for "C:\\docs\\code" in key:

Which works fine and will return "C:\\docs\\code" : 20,
"C:\\docs\\code\\snippets" : 5, "C:\\docs\\code\\python" : 10 = (35)

However it fails when I try to calculate the size of a directory such as
"C:\\docs", as it also returns "C:\\docs123".

I'd be very grateful if anyone could offer any advice on how to correct
this.


More information about the Tutor mailing list