I have a dictionary [CODE]dict1={'18':['4000','1234'],'12':['7000','4821','187','1860','123','9000']}[/CODE] I want to sort the keys and values such that, the output is, [CODE]dict1={'12':['123','187','1860','4821','7000','9000'],'18':['1234','4000']}[/CODE] I tried something! but it didn work [CODE]>>> for values in dict1: ... dict1[values].sort() ... >>> dict1 {'18': ['1234', '4000'], '12': ['123', '1860', '187', '4821', '7000', '9000']}[/CODE] Full sorting happens for values of '18'. The values of '12' are partially sorted. but '18' and '12' are themselves not sorted. I don't know whats happening!

Member Avatar
Member Avatar
+0 forum 10

A service running in the Server is listening to port 2978 on 1xx.xxx.xx.xx for incoming connections! My PHP code receives URL data through get method. A tcp connection has to be established with the 'service' on that port and the data received from the URL should be sent to the service. The service responds with another data to the same port. this data should be obtained by the code and be saved in a file. I've written the code. But its showing error! help me pls!! [CODE]#!/usr/local/php5/bin/php-cgi <?php $CONTENT = $_GET["DATA"]." "; //fsockopen("tcp://1xx.xxx.xx.xx",2978 , $errno, $errstr, 30); echo urldecode($CONTENT); $Handle …

Member Avatar
Member Avatar
+0 forum 1

<text> <p><s id="s1"><ng><w pws="yes" id="w1" p="CD">25</w> <w l="woman" pws="yes" id="w4" p="NNP" common="true" headn="yes">Woman</w></ng> <vg tense="past" voice="act" asp="simple" modal="no"><w l="create" pws="yes" id="w10" p="VBD" headv="yes">created</w></vg> <pg><w pws="yes" id="w18" p="IN">for</w></pg> <ng><w vstem="succeed" l="success" pws="yes" id="w22" p="NN" headn="yes">success</w> <w l="barbie" pws="yes" id="w30" p="NN" headn="yes">barbie</w></ng> <ng><enamex type="location"><w l="reynold" pws="yes" id="w37" p="NNP" locname="single">Reynolds</w></enamex> <w l="sep" pws="yes" id="w46" p="NN" headn="yes">sep</w></ng> <ng><timex type="date"><w pws="yes" id="w50" p="CD">1986</w></timex></ng> <ng><enamex type="organization"><w l="pari" pws="yes" id="w55" p="NNP" locname="single">Paris</w> <w orgname="single" l="google" pws="yes" id="w61" p="NNP">Google</w> <w l="limited" pws="yes" id="w68" p="NNP" common="true">Limited</w></enamex></ng></s></p> </text> ========================================================= From the above XML, i want to get content between <enamex type="location"><w l="reynold" pws="yes" id="w37" p="NNP" locname="single">[COLOR="Red"]Reynolds[/COLOR]</w></enamex> I want to retrieve …

Member Avatar
Member Avatar
+0 forum 1

Hi, I am building a simple android application that sends GPS coordinates from an Android phone to a Webserver, and the received co-ordinates are displayed one by one in the server. I think both my client and server side programs are correct, but I am not sure. Please correct the code if its not correct. Where/How can I see the received co-ordinates? Also I need to see it like this [CODE]Latitude Longitude 55.17 -3.48 52.18 -2.11 50.23 -1.45[/CODE] the 1st 55.17 and -3.48 are displayed when the server receives it and both 55.17,-3.48 and 52.18,-2.11 are displayed when the second …

Member Avatar
+0 forum 0

D is a list containing some words. D=[word1,word2,word3......] E is a list containing combinations of any two words in D ... E=[(word1,word2),(word7,word1)....] How can I implement the following in python: [CODE]A0[x]=1 for all x in D # This is actually Ai. when i=0, it becomes A0 B0[x]=1 for all x in D for i = 1 to 10: # i takes the values 1 to 10 Ai[x]=0 for all x in D Bi[x]=0 for all x in D for x in D: for y in D: if (x,y) in E: Bi[x]=bi[x] + Ai-1[q] if (y,x) in E: Ai[p]=Ai[p]+Hi-1[q] print A10,B10[/CODE]

Member Avatar
Member Avatar
+0 forum 6

Hi can anyone tell me how to remove empty keys in the following dictionary d={'a':[],'b':['1','2'],'c':[]} I want it to be d={'b':['1','2']} I tried this. But its showing error. I know its wrong to change the size of a dictionary during iteration. But is there any other way? [CODE]>>> for x in d: ... if d[x]==[]: ... del d[x] ... Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: dictionary changed size during iteration[/CODE]

Member Avatar
Member Avatar
+0 forum 6

We know that 0.1 + 0.1 + 0.1 - 0.3 = 0.0 But in python 0.1 + 0.1 + 0.1 - 0.3 = 5.5511151231257827e-017 Is there any way I can get 0.0...??

Member Avatar
Member Avatar
+0 forum 5

I have a list [CODE]x = ['abc','1','2','3','def','6','8','5','13','mcg','568','35469','6453'][/CODE] I want the output file in a dictionary as follows: [CODE]dict = {'abc':['1','2','3'],'def':['6','8','5','13'],'mcg':['568','35469','6453']}[/CODE] How can i do this?

Member Avatar
Member Avatar
+0 forum 13

I have dictionary with single element lists. [CODE]dictionary={'a':['A'], 'b':['B'], 'c':['C']} [/CODE] How can i change it to [CODE]{'a':'A', 'b':'B','c':'C'}[/CODE]

Member Avatar
Member Avatar
+0 forum 4

I dont know what goes wrong in this piece of code?!! I keep getting the following error. File "<stdin>", line 11 t1.append(list[temp]) ^ SyntaxError: invalid syntax [CODE]tl = [] for inlist in token_list: temp=[] for token in inlist: temp.append((zlib.adler32(token,65521)) tl.append(temp)[/CODE]

Member Avatar
Member Avatar
+0 forum 6

I have a list of lists [CODE]x=[['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']][/CODE] I need the following output. [CODE]a-b a-c a-d b-c b-d c-d e-f g-h[/CODE] How can i do this? Can a regular expression be used here??

Member Avatar
Member Avatar
+0 forum 4

I have a file named test.txt I get the file [CODE]file=open("test.txt","r") obj=file.read() file.close() print obj a=a b=b c=c d=e e=d e=f f=e f=g g=h[/CODE] All I want to do with this obj is that, I've to create a regular expression such that, 1.If the left number matches the right number, it should become a single number.ie., a=a should become a. 2.Then d=e & e=d means the same. In this case any one of them must be removed. So as for e=f & f=e. 3. Notice the newlines. Some have \n ,some have \n\n and some have \n\n\n . Make everything …

Member Avatar
Member Avatar
+0 forum 4

I have a set of text files in a folder. I want to read each file, convert the contents of the file to lowercase, remove punctuations and save them all in another directory with the same filenames. How can i do that???

Member Avatar
Member Avatar
+0 forum 2

I have 2 lists X=['a'] Y=['b','c','d','e','f'] I need to make a new list Z such that, Z = ['ab','ac','ad','ae','af'] I know this uses simple concatenation. I tried several times but without success. I am a beginner so please help me with the code. Thanks in advance.

Member Avatar
Member Avatar
+0 forum 2

The End.