Python Forum
How to pass value from method to function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to pass value from method to function
#4
Stop writing classes

what is the purpose to write a class with the only purpose to return an element of a list that you pass as argument at the time of instantiation?
if that is some weird test question


from single_method_list import SingleMethodList


def list_length(single_method_list):      # This is how I have done it and it works.
   single_method_list = MyClass([i for i in range(0, 234589)])

   for x in (10**p for p in range(1, 8)):
       if single_method_list.get(x):
           print("More than", x)
           first = x
       else:
           print("Less than", x)
           last = x
           break

   answer = False
   while not answer:
       result = (first + last)/2
       result = int(round(result))
       print(result)
       if single_method_list.get(result):
           first = result
           print('first', result)
       else:
           last = result
           print('last', result)

       if single_method_list.get(result) and not single_method_list.get(result + 1):
           answer = True
           print(result + 1)


a_list = SingleMethodList(list(range(0, 234589))) # python3
#a_list = SingleMethodList(range(0, 234589)) #python2 - I don't understand why test case use list comprehension from xrange, instead of simply range
it looks like you use python3 and test case is using python2. Note - I just adjusted your code, did not correct algorithm or code/style
Reply


Messages In This Thread
RE: How to pass value from method to function - by buran - May-23-2017, 01:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to pass encrypted pass to pyodbc script tester_V 0 936 Jul-27-2023, 12:40 AM
Last Post: tester_V
  i want to use type= as a function/method keyword argument Skaperen 9 2,052 Nov-06-2022, 04:28 AM
Last Post: Skaperen
Question How to pass a method as argument in an another method? anilanvesh 6 2,835 Sep-30-2021, 10:18 PM
Last Post: deanhystad
  Regex - Pass Flags as a function argument? muzikman 6 3,742 Sep-06-2021, 03:43 PM
Last Post: muzikman
  Possible to dynamically pass arguments to a function? grimm1111 2 2,281 Feb-21-2021, 05:57 AM
Last Post: deanhystad
  Building a method name in a function ffgth 9 3,390 Oct-19-2020, 01:21 PM
Last Post: buran
  Do I have to pass 85 variables to function? Milfredo 10 4,449 Sep-26-2020, 10:13 PM
Last Post: Milfredo
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,622 Sep-07-2020, 08:02 AM
Last Post: perfringo
  Pass integers to datetime.date function florian 3 2,792 Jul-18-2020, 04:43 AM
Last Post: scidam
  How to pass multiple arguments into function Mekala 4 2,533 Jul-11-2020, 07:03 AM
Last Post: Mekala

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020