Hello
I just want to update the data inside List or Dictionary without
adding or deleting object.
is this correct ?
l=[1, 2, 3]
for i, v in enumerate(l):
l[i]=v+1
d=dict(a=1, b=2, c=3)
for k, v in d.iteritems():
d[k]=d[k]+1
Both works, but :
are they correct ?
are they optimum for big structure ?
Thanks 2 1180
d=dict(a=1, b=2, c=3)
for k, v in d.iteritems():
d[k]=d[k]+1
You might as well do: d[k] = v + 1, like for the list.
On 24 mai, 19:21, "Christopher Anderson" <sidewinder....@gmail.com>
wrote:
d=dict(a=1, b=2, c=3)
for k, v in d.iteritems():
d[k]=d[k]+1
You might as well do: d[k] = v + 1, like for the list.
ops, yes it was a typo This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rakesh |
last post by:
Hi,
For a particular problem of mine, I want to sort <key, value> pairs
by its value.
Eg:
Input:
A, 4
B, 5
|
by: vatamane |
last post by:
This has been bothering me for a while. Just want to find out if it
just me or perhaps others have thought of this too: Why shouldn't the
keyset of a dictionary be represented as a set instead of a...
|
by: buzzweetman |
last post by:
Many times I have a Dictionary<string, SomeTypeand need to get the
list of keys out of it as a List<string>, to pass to a another method
that expects a List<string>.
I often do the following:
...
|
by: Macca |
last post by:
Hi,
My app needs to potentially store a large number of custom objects and be
able to iterate through them quickly. I was wondering which data structure
would be the most efficient to do this,a...
|
by: O.B. |
last post by:
I need the ability to parse through the values of a Dictionary and
remove certain ones depending on their attribute values. In the example
below, an InvalidOperationException is thrown in the...
|
by: Alan |
last post by:
I was wondering whether it is good programming practice or asking
for trouble to modify a vector while iterating through it. That is, I
want to do something like the following pseudocode in C++:
...
|
by: dustin.getz |
last post by:
consider the following working loop where Packet is a subclass of
list, with Packet.insert(index, iterable) inserting each item in
iterable into Packet at consecutive indexes starting at index.
...
|
by: ++imanshu |
last post by:
Hi,
Wouldn't it be nicer to have 'in' return values (or keys) for both
arrays and dictionaries. Arrays and Dictionaries looked so similar in
Python until I learned this difference.
Thanks,...
|
by: Terry Reedy |
last post by:
SUBHABRATA, I recommend you study this excellent response carefully.
castironpi wrote:
It starts with a concrete test case -- an 'executable problem
statement'. To me, this is cleared and...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |