Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 20th, 2012, 07:02 PM
darnold4014 darnold4014 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 darnold4014 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 43 sec
Reputation Power: 0
Pyhton troubles..

I have been promted with this question and have been throughly stumped... Please help, Thanks!

Write an algorithm for each of the following python operations and test you algorithm by writing a it up in a suitable function. You are not allowed to use the corresponding Python method to implement your function. a. count(myList, x) (like myList.count(x)) b. isin(myList, x) (like x in myList)) c. index(myList, x) (like myList.index(x)) d. reverse(myList) (like myList.reverse()) e. sort(myList) (like myList.sort())

Reply With Quote
  #2  
Old November 20th, 2012, 07:58 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,384 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 48 m 49 sec
Reputation Power: 383
Here's an example.
Code:
def count(L,o):

    '''
        A doctest providing supporting evidence that
        the function might be correct.
        >>> a='forty-five'
        >>> a.count('f') == count(a,'f')
        True
    '''

    # longer, but still probably shorter than your version, that is, if you bothered to write a solution
    occurrences = 0
    for obj in L:
        occurrences += obj == o
    return occurrences

    # short form
    return sum(obj == o for obj in L)
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old November 21st, 2012, 03:40 PM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 483 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 51 m 26 sec
Reputation Power: 63
One possibility:
Code:
def list_reverse(mylist):
    return mylist[::-1]

mylist = list('abcde')
print(list_reverse(mylist))
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

Reply With Quote
  #4  
Old November 22nd, 2012, 12:22 AM
hovestar hovestar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 13 hovestar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 44 m 21 sec
Reputation Power: 0
Lucky for me I wrote a sorting function today, because I wanted to sort 2 lists with corresponding indexes, Here it is:

Code:
temp = []
while(len(fitness) >=1):
  temp.append(fitness[fitness.index(max(fitness))])
  del fitness[fitness.index(max(fitness))]


it sorts highest to lowest.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Pyhton troubles..

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap