Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 9th, 2008, 6:16 PM   #1
goblin4u
Newbie
 
Join Date: Oct 2008
Posts: 4
Rep Power: 0 goblin4u is on a distinguished road
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.
goblin4u is offline   Reply With Quote
Old Oct 9th, 2008, 6:31 PM   #2
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
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 letter

Do 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 not

Do 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 item


Put 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.
Sane is offline   Reply With Quote
Old Oct 9th, 2008, 6:52 PM   #3
goblin4u
Newbie
 
Join Date: Oct 2008
Posts: 4
Rep Power: 0 goblin4u is on a distinguished road
Re: Deleting first occurrence in a list

Thanks Sane i will try to do what you said and see if it works
goblin4u is offline   Reply With Quote
Old Oct 9th, 2008, 7:47 PM   #4
goblin4u
Newbie
 
Join Date: Oct 2008
Posts: 4
Rep Power: 0 goblin4u is on a distinguished road
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?
goblin4u is offline   Reply With Quote
Old Oct 9th, 2008, 9:08 PM   #5
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old Oct 9th, 2008, 10:03 PM   #6
goblin4u
Newbie
 
Join Date: Oct 2008
Posts: 4
Rep Power: 0 goblin4u is on a distinguished road
Re: Deleting first occurrence in a list

I mean just return string 1 without the "a" in it...
goblin4u is offline   Reply With Quote
Old Oct 9th, 2008, 10:45 PM   #7
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC