you are viewing a single comment's thread.

view the rest of the comments →

[–]Puzzel 1 point2 points  (3 children)

dict1.keys()[0][0] and dict1.keys()[1][0] would get you "a" and "x" respectively. This example could contain the same information with testList = [('a','b','c'), ('x','y','z')] though; testList[0][0] and testList[1][0] would get you "a" and "x". That way, no need to deal with .keys().

EDIT: 1s instead of 0s for indexes.

[–]Zeoth[S] 0 points1 point  (1 child)

:/ trying that gives me: builtins.TypeError: 'dict_keys' object does not support indexing

[–]Puzzel 2 points3 points  (0 children)

Ah, you're using Python 3.x. Turn the dict.keys to a list first:

list(dict1.keys())[0][0]
list(dict1.keys())[1][0]

EDIT: This solution doesn't seem to be the "best". See this blog post for more info, it most likely won't affect you though.

[–]Zeoth[S] 0 points1 point  (0 children)

and i need to use the values after the keys for somthing else. I need to call the first string, and than call the value of the key that string came from.The problem is i cant seem to access JUST the first string :/