"Graps Graps" wrote:
Text2 is a python dictionary containing data as
{0: 'a', 1: 'b', 2: 'c'...}
now I want the data in text1 to be replaced with the keys, say like
0 1
0 2
0 3
0 6
1 2... so on..
someone asked a very similar question not long ago, so maybe you're
really supposed to figure this out yourself. I'm sure your teacher
won't kill you if you ask for a hint.
(if you asked me for a hint, I'd tell you to look for questions about
dictionaries in the mailing list archives).
</F> 1 1447
Hi all..,
I tried with this..
def multiple_replac e(text,adict):
rx=re.compile(' |'.join(map(re. escape,adict)))
def one_xlat(match) :
return adict[match.group(0)]
return rx.sub(one_xlat ,text)
print multiple_replac e(text,adict)
I am thrown with a error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in multiple_replac e
TypeError: argument 2 to map() must support iteration
I would be grateful for any comments..
Thankin in advance'
GraPs.
Fredrik Lundh wrote:
"Graps Graps" wrote:
Text2 is a python dictionary containing data as
{0: 'a', 1: 'b', 2: 'c'...}
now I want the data in text1 to be replaced with the keys, say like
0 1
0 2
0 3
0 6
1 2... so on..
someone asked a very similar question not long ago, so maybe you're
really supposed to figure this out yourself. I'm sure your teacher
won't kill you if you ask for a hint.
(if you asked me for a hint, I'd tell you to look for questions about
dictionaries in the mailing list archives).
</F>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Xah Lee |
last post by:
suppose you want to do find & replace of string of all files in a
directory.
here's the code:
©# -*- coding: utf-8 -*-
©# Python
©
©import os,sys
©
©mydir= '/Users/t/web'
|
by: andrea.gavana |
last post by:
Hello NG,
probably this is a basic question, but I'm going crazy... I am unable
to find an answer. Suppose that I have a file (that I called "Errors.txt")
which contains these lines:
MULTIPLY
'PERMX' @PERMX1 1 34 1 20 1 6 /
'PERMX' @PERMX2 1 34 21 41 1 6 /
'PERMX' @PERMX3 1 34 1 20 7 14 /
|
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: rbt |
last post by:
Here's the scenario:
You have many hundred gigabytes of data... possible even a terabyte or
two. Within this data, you have private, sensitive information (US
social security numbers) about your company's clients. Your company has
generated its own unique ID numbers to replace the social security numbers.
Now, management would like the IT guys to go thru the old data and
replace as many SSNs with the new ID numbers as possible. You...
|
by: ProvoWallis |
last post by:
I'm still learning python so this might be a crazy question but I
thought I would ask anyway. Can anyone tell me if it is possible to
join two dictionaries together to create a new dictionary using the
keys from the old dictionaries?
The keys in the new dictionary would be the keys from the old
dictionary one (dict1) and the values in the new dictionary would be
the keys from the old dictionary two (dict2). The keys would be joined
by...
| |
by: Rico |
last post by:
I'm moving some queries out of an Access front end and creating views out of
them in SQL Server 2005 express. In some of the numeric fields, I use nz
quite often, ( i.e. nz(,0)) to return a zero if the field is null.
Is there anything equivalent to this in SQL Server? Right now I'm using
CASE WHEN ... but it seems like an awful lot of script to write just to
replace null with a zero.
Any help would be greatly appreciated.
Thanks!
|
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 list? I
know that sets were introduced a lot later and lists/dictionaries were
used instead but I think "the only correct way" now is for the
dictionary keys and values to be sets. Presently {1:0,2:0,3:0}.keys()
will produce but it could also...
|
by: f pemberton |
last post by:
I have a string (xdata) and theres a newline after every 17 characters
of the string. I was wondering how I can replace multiple substrings
multiple times within a string? To put it another way, this is what i
want to do.
Substring to find ("abcdef") replace it with ("highway")
search again, substring to find ("defgef") replace it with
("news").Search again and find ("effwer") replace it with
("monitor").Example string to search under...
|
by: Nader |
last post by:
Hello,
I have a dictionary and will get all keys which have the same values.
d = {('a' : 1), ('b' : 3), ('c' : 2),('d' : 3),('e' : 1),('f' : 4)}
I will something as :
d.keys(where their values are the same)
|
by: Florian Brucker |
last post by:
Hi everybody!
Given a dictionary, I want to create a clustered version of it,
collecting keys that have the same value:
{1:, 2:, 3:}
That is, generate a new dict which holds for each value of the old dict
a list of the keys of the old dict that have that very value.
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |