I dispose of a dictionary whose values look like a list of strings (d_pro): - d_pro={'1': ['1,2,3', '4,5,6'], '2': ['1,2,3', '4,5,6']}
I'd like to turn it into a dictionary whose values look like a list of lists (expected output in d_pro_list) for further processing: - d_pro_list= {'1': [['1,2,3'], ['4,5,6']], '2': [['1,2,3'], ['4,5,6']]}
I'm trying the given code: - d_pro_list={}
-
for k in d_pro.keys():
-
for v in d_pro.values():
-
for i in v:
-
d_pro_list[k]= [i]
But the output is like: - d_pro_list= {'1': ['1,2,3,4,5,6'], '2': ['1,2,3,4,5,6']}
Can you please help me finding my mistakes? Thanks.
1 1213 bvdet 2,851
Recognized Expert Moderator Specialist
I am unsure how you actually want it, so I will show both: -
>>>
-
>>> d_pro={'1': ['1,2,3', '4,5,6'], '2': ['1,2,3', '4,5,6']}
-
>>> for key in d_pro:
-
... d_pro[key] = [item.split(",") for item in d_pro[key]]
-
...
-
>>> d_pro
-
{'1': [['1', '2', '3'], ['4', '5', '6']], '2': [['1', '2', '3'], ['4', '5', '6']]}
-
>>> d_pro={'1': ['1,2,3', '4,5,6'], '2': ['1,2,3', '4,5,6']}
-
>>> for key in d_pro:
-
... d_pro[key] = [[item] for item in d_pro[key]]
-
...
-
>>> d_pro
-
{'1': [['1,2,3'], ['4,5,6']], '2': [['1,2,3'], ['4,5,6']]}
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: MackS |
last post by:
Dear all,
I've got several large sets in my program. After performing several
operations on these I wish to present one set to the user
sorted according to a certain criterion. Is there any direct way to do
so? Or must I
list =
for item in set1:
|
by: Stephen |
last post by:
Hi Everyone
I'm going to use my first <asp:CheckBoxList> control to create a list of
selections which users can choose from and run a search against. In other
words they are going to act as the parameters of query.
I want to store the values in the web-config and then bind to the values to
the checkbox list.
Has anyone done anything...
|
by: Siemel Naran |
last post by:
Hi. I have found one advantage of returning values through the argument
list. It's that we have to store the return value. But when we return by
value, we may forgot to store the return value.
Consider,
void f(int x, int& i);
int i, j;
f(1, i);
|
by: metiu uitem |
last post by:
Say you have a flat list:
How do you efficiently get
, , ]
I was thinking of something along the lines of:
for (key,number) in list:
print key, number
|
by: Zlatko Matić |
last post by:
Hello.
How to reference selected values from a multi-select list box, as a
criteria in a query ?
Is it possible at all?
Regards,
Zlatko
| |
by: metaperl.etc |
last post by:
The following program does not work if you uncomment #lis =
+ list(args)
Evidently Python is opting for the nullary constructor list() as
opposed to the other one which takes a sequence. But no newcomer would
know this. And the Python docs dont give a good example of dealing with
taking a sequence of args and converting it to a list.
...
|
by: j1o1h1n |
last post by:
Hello,
I was trying to create a flattened list of dictionary values where each
value is a list, and I was hoping to do this in some neat functionally
style, in some brief, throwaway line so that it would assume the
insignificance that it deserves in the grand scheme of my program.
I had in mind something like this:
|
by: zefciu |
last post by:
Hi!
I want to embed a function in my python application, that creates a
two-dimensional array of integers and passes it as a list (preferably a
list of lists, but that is not necessary, as the python function knows
the dimensions of this array). As I read the reference, I see, that I
must first initialize a list object and then...
|
by: psbasha |
last post by:
Hi,
Is it not possible to reference other than Dict,tuples ,strings and list datatypes /variables ,when we call the functions?
Say int,float and boolean
Thanks
PSB
|
by: Loginalyn |
last post by:
i am doing a Point of Sales sytem.i am having trouble on how will i add all the integer values entered in a list box by clicking a command button with a corresponding integer value.
i want to compute the sum of those integers when i click the compute button. can someone give me an idea or a sample code?
Thanks in advance!
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |