Hello everyone,
I have a bit of code that I want to repeat for a string. I keep getting infinite while loops when I try it though. Any thoughts on where I am going wrong?
Thanks,
Mark
original code: -
tvshow = {}
-
start = data.find( '>')
-
end = data.find( '\n', start+1)
-
firstname = data[start:end]
-
start2 = data.find ( '\n', start)
-
end2 = data.find( '\n', start2 + 1 )
-
start2 = start2 + 1
-
lastname = data[start2:end2]
-
tvshow[firstname] = lastname
-
loop code: -
tvshow = {}
-
start = 0
-
a = 0
-
-
while (data):
-
if start != -1:
-
-
start = data.find( '>')
-
end = data.find( '\n', start+1)
-
firstname = data[start:end]
-
start2 = data.find ( '\n', start)
-
end2 = data.find( '\n', start2 + 1 )
-
start2 = start2 + 1
-
lastname = data[start2:end2]
-
tvshow[firstname] = lastname
-
start += 1
-
end += 1
-
start2 += 1
-
end2 += 1
-
else:
-
break
-
5 1832
Hello everyone,
I have a bit of code that I want to repeat for a string. I keep getting infinite while loops when I try it though. Any thoughts on where I am going wrong?
Thanks,
Mark
original code: -
tvshow = {}
-
start = data.find( '>')
-
end = data.find( '\n', start+1)
-
firstname = data[start:end]
-
start2 = data.find ( '\n', start)
-
end2 = data.find( '\n', start2 + 1 )
-
start2 = start2 + 1
-
lastname = data[start2:end2]
-
tvshow[firstname] = lastname
-
loop code: -
tvshow = {}
-
start = 0
-
a = 0
-
-
while (data):
-
if start != -1:
-
-
start = data.find( '>')
-
end = data.find( '\n', start+1)
-
firstname = data[start:end]
-
start2 = data.find ( '\n', start)
-
end2 = data.find( '\n', start2 + 1 )
-
start2 = start2 + 1
-
lastname = data[start2:end2]
-
tvshow[firstname] = lastname
-
start += 1
-
end += 1
-
start2 += 1
-
end2 += 1
-
else:
-
break
-
how about correcting your indentation first
bvdet 2,851
Recognized Expert Moderator Specialist
Hello everyone,
I have a bit of code that I want to repeat for a string. I keep getting infinite while loops when I try it though. Any thoughts on where I am going wrong?
Thanks,
Mark
original code: -
tvshow = {}
-
start = data.find( '>')
-
end = data.find( '\n', start+1)
-
firstname = data[start:end]
-
start2 = data.find ( '\n', start)
-
end2 = data.find( '\n', start2 + 1 )
-
start2 = start2 + 1
-
lastname = data[start2:end2]
-
tvshow[firstname] = lastname
-
loop code: -
tvshow = {}
-
start = 0
-
a = 0
-
-
while (data):
-
if start != -1:
-
-
start = data.find( '>')
-
end = data.find( '\n', start+1)
-
firstname = data[start:end]
-
start2 = data.find ( '\n', start)
-
end2 = data.find( '\n', start2 + 1 )
-
start2 = start2 + 1
-
lastname = data[start2:end2]
-
tvshow[firstname] = lastname
-
start += 1
-
end += 1
-
start2 += 1
-
end2 += 1
-
else:
-
break
-
Can you show us a sample of the string? In your code, there seems to be no way for the variable 'start' to ever be -1, so the loop would never end. You could break the string up by splitting on '\n' and extract the data by iterating on the list.
Thanks for the replies.
My thinking was that when there is no data left in the string I am reading (which I read in from a file), then start would equal -1.
The sample data I am working with is:
>Musmusculuslet-7g
UGAGGUAGUAGUUUGUACAGU
>Musmusculuslet-7i
UGAGGUAGUAGUUUGUGCUGU
>MusmusculusmiR-1
UGGAAUGUAAAGAAGUAUGUA
I also practiced by using this:
>Jerry
Seinfeld
>Cosmo
Kramer
what is the problem with the indentation?
Mark
bvdet 2,851
Recognized Expert Moderator Specialist
I would think a solution like this would be better: - s = ">Musmusculuslet-7g\nUGAGGUAGUAGUUUGUACAGU\n>Musmusculuslet-7i\nUGAGGUAGUAGUUUGUGCUGU\n>MusmusculusmiR-1\nUGGAAUGUAAAGAAGUAUGUA"
-
-
dd = {}
-
sList = s.split()
-
while len(sList) > 0:
-
dd[sList.pop(0)] = sList.pop(1)
-
-
print dd
Output: >>> {'>Musmusculuslet-7i': 'UGAGGUAGUAGUUUGUGCUGU', '>MusmusculusmiR-1': 'UGGAAUGUAAAGAAGUAUGUA', '>Musmusculuslet-7g': 'UGAGGUAGUAGUUUGUACAGU'}
>>>
Thanks! That has done the trick
Mark
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kamilche |
last post by:
I was looking for a way to speed up detecting invalid characters in my
TCP string, and thought of yet another use for the translate function!
If you were to 'translate out' the bad characters, and...
|
by: No Such Luck |
last post by:
I have a function which requires me to loop from the end of a string to
the beginning on a char by char basis:
int foo (char string)
{
unsigned int i;
for(i = strlen(string); i >= 0; i--)
{...
|
by: Paul |
last post by:
hi, there,
for example,
char *mystr="##this is##a examp#le";
I want to replace all the "##" in mystr with "****". How can I do this?
I checked all the string functions in C, but did not...
|
by: Chad Myers |
last post by:
I've been perf testing an application of mine and I've noticed that there
are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String
instances being created.
I've done some...
|
by: Cor |
last post by:
Hallo,
I have promised Jay B yesterday to do some tests.
The subject was a string evaluation that Jon had send in. Jay B was in doubt
what was better because there was a discussion in the C#...
|
by: Brian Mitchell |
last post by:
Is there an easy way to pull a date/time stamp from a string? The DateTime
stamp is located in different parts of each string and the DateTime stamp
could be in different formats (mm/dd/yy or...
|
by: bcpkh |
last post by:
Hello All
I need to check a string to make sure it does not contain any non
numeric characters, the problem that I face is that the string is
fairly long, 2784601121574585949, strtol etc. can't...
|
by: kellysgirl |
last post by:
Now what you are going to see posted here is both the set of instructions I was given..and the code I have written.
The instructions I was given are as follows
In this case, you will create...
|
by: chellemybelle |
last post by:
Hello,
I basically have made a little cheezy slideshow and would like to add captions to each pic as it loops through. I've tried everything I can think of. I'm assuming I might need to use an...
|
by: yogi_bear_79 |
last post by:
I'm sure I have a few things wrong here. But I am stuck on how to do
a recurring search. Also my statement cin >quote; acts weird. If I
enter more than one word it blows right past cin >findMe;...
|
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: 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...
|
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...
|
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: 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...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |