For example in python:
employees[x][i] = float(employees[x][i]) The two brackets mean you're accessing an element in a list of lists (or dictionaries)
So in this example, it might look something like this
In [17]: employees = {'joe': ['100', 0], 'sue': ['200', 0]} In [18]: x = 'joe' In [19]: i = 0 In [20]: employees[x][i] Out[20]: '100' employees or employees[x] object, not by whether the thing inside the brackets is a string or an integer. Integers can be dictionary keys, but strings cannot be array indexes.I put in extra parens to show how this is evaluated
(employees[x])[I] = float((employees[x])[i]) and an example
>>> foo = dict(name="Foo", salary=10.00) >>> bar = dict(name="Bar", salary=12.00) >>> employees = dict(foo=foo, bar=bar) >>> employees {'foo': {'salary': 10.0, 'name': 'Foo'}, 'bar': {'salary': 12.0, 'name': 'Bar'}} >>> employees['foo']['name'] 'Foo' >>> employees['bar']['salary'] 12.0 employees could also be a list (or any other kind of container)
>>> employees = [foo, bar] >>> employees [{'salary': 10.0, 'name': 'Foo'}, {'salary': 12.0, 'name': 'Bar'}] >>> employees[0]['name'] 'Foo' >>> employees[1]['salary'] 12.0 Syntax meaning of [] in python:
In python, [] operator is used for at least three purposes (maybe incomplete):
Thing goes complex when embedding [] in [] or [] next to [], see examples below:
matrix = [[0,1],[2,3]] e01 = matrix[0][1] people = [{'fname':'san','lname':'zhang'}, {'fname':'si', 'lname':'li'}] last1 = people[1]['lname'] [[]] and [][] are reciprocal to each other.
employees[x][i]represents a value,, this syntax will just convert your value tofloatand store it back...