![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2008
Posts: 4
Rep Power: 0
![]() |
Deleting first occurrence in a list using Python
Hey, guys i am new to programming and i have an assignment to do and one of the things that they ask me to do is to remove the first occurrence from a list which contains two strings with out using any string methods, so that's where i am stuck.
Here is an example to see what i am talking about, For example the given list = ("fffabcdefffg", "f"), and i have to make a program that returns "abcdefffg", so any help with this will be appreciated, sorry if this is confusing this is my first post ![]() Last edited by goblin4u; Oct 9th, 2008 at 6:27 PM. |
|
|
|
|
|
#2 |
|
Banned
![]() ![]() |
Re: Deleting first occurrence in a list
Do you know how to loop through a string?
my_str = "fffabcdefffg"
for letter in my_str:
print letter # This executes for each letterDo you know how to build a string? my_str = '' my_str = my_str + 'a' my_str = my_str + 'b' my_str = my_str + 'c' print my_str # Should print "abc" Do you know how to use an if condition? my_letter = 'a'
letter = 'a'
if letter == my_letter:
print "Yes" # This executes if they match
else:
print "No" # This executes if they do notDo you know how to access the first and second item of a tuple? lst = ("fffabcdefffg", "f")
print lst[0] # print the first item
print lst[1] # print the second itemPut all of these building blocks together logically, and you should have your code. Do a little experimentation. Try some stuff out. Post code that you think should work and then ask some questions about it.
__________________
Looking for tough programming challenges? Try participating in Sane's Monthly Algorithms Challenges! Composing Techno is a little side hobby of mine. Techno by DJ Sane. All free for download. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2008
Posts: 4
Rep Power: 0
![]() |
Re: Deleting first occurrence in a list
Thanks Sane i will try to do what you said and see if it works
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Oct 2008
Posts: 4
Rep Power: 0
![]() |
Re: Deleting first occurrence in a list
Hey Sane i tried to play around with it now i am stuck at the part where i have 2 strings
string1 = "aaabcdeabcd" string2 = "a" is there a code which allows me to skip string2 from string1? |
|
|
|
|
|
#5 |
|
Banned
![]() ![]() |
Re: Deleting first occurrence in a list
What do you mean by "skip"...?
__________________
Looking for tough programming challenges? Try participating in Sane's Monthly Algorithms Challenges! Composing Techno is a little side hobby of mine. Techno by DJ Sane. All free for download. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Oct 2008
Posts: 4
Rep Power: 0
![]() |
Re: Deleting first occurrence in a list
I mean just return string 1 without the "a" in it...
|
|
|
|
|
|
#7 |
|
Banned
![]() ![]() |
Re: Deleting first occurrence in a list
Just think about it logically step by step. Write the Psuedocode (English explanation of the code), and then translate it to code using the examples I showed you. You can do the entire problem with those little bits of code plus some extra variable declarations. I'm not writing it for you, but I can answer questions if you ask me why your code doesn't work (which I have not seen any of, incidently).
__________________
Looking for tough programming challenges? Try participating in Sane's Monthly Algorithms Challenges! Composing Techno is a little side hobby of mine. Techno by DJ Sane. All free for download. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| linked list problems | bl00dninja | C++ | 6 | Feb 17th, 2008 11:30 AM |
| Linked List problem - Deleting a node | Brent | C++ | 9 | Dec 16th, 2007 4:39 PM |
| singly-linked list templaste class in C++ w/ example driver | bl00dninja | Show Off Your Open Source Projects | 0 | Sep 11th, 2006 2:05 AM |
| User-defined creatNode and deleteNode functions for a doubly-linked list | jgs | C | 2 | Apr 28th, 2005 9:53 AM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 5:12 PM |