Hi
is there anyway appending to dictionary?
list has this feature
[color=blue][color=green][color=darkred]
>>>a = []
>>>a.append(1 )
>>>print a[/color][/color][/color]
[1]
but dictionary can't
i wanna do like this thing[color=blue][color=green][color=darkred]
>>>a = {1, 2}
>>>a.append(3 , 4) -> This is just my idea :@
>>>print a[/color][/color][/color]
{1:2, 3:4}
so i try this feature like[color=blue][color=green][color=darkred]
>>>a = {1, 2}
>>>a = dict(zip(a.keys ().append(3), a.values().appe nd(4)))[/color][/color][/color]
but this make's error
because a.keys().append (3) makes 'None' (i can't understand this :( )
so i try[color=blue][color=green][color=darkred]
>>>import copy
>>>a = dict(zip(copy.c opy(a.keys()).a ppend(3),[/color][/color][/color]
copy.copy(a.val ues()).append(4 )))
and
a = dict(zip(copy.d eepcopy(a.keys( )).append(3),
copy.deepcopy(a .values()).appe nd(4)))
but this make's error, too
why a.keys().append (3) makes 'None' ?
and is there anyway appending to dictionary?
any post will be appreciated :)
is there anyway appending to dictionary?
list has this feature
[color=blue][color=green][color=darkred]
>>>a = []
>>>a.append(1 )
>>>print a[/color][/color][/color]
[1]
but dictionary can't
i wanna do like this thing[color=blue][color=green][color=darkred]
>>>a = {1, 2}
>>>a.append(3 , 4) -> This is just my idea :@
>>>print a[/color][/color][/color]
{1:2, 3:4}
so i try this feature like[color=blue][color=green][color=darkred]
>>>a = {1, 2}
>>>a = dict(zip(a.keys ().append(3), a.values().appe nd(4)))[/color][/color][/color]
but this make's error
because a.keys().append (3) makes 'None' (i can't understand this :( )
so i try[color=blue][color=green][color=darkred]
>>>import copy
>>>a = dict(zip(copy.c opy(a.keys()).a ppend(3),[/color][/color][/color]
copy.copy(a.val ues()).append(4 )))
and
a = dict(zip(copy.d eepcopy(a.keys( )).append(3),
copy.deepcopy(a .values()).appe nd(4)))
but this make's error, too
why a.keys().append (3) makes 'None' ?
and is there anyway appending to dictionary?
any post will be appreciated :)
Comment