Skip to main content
added 14 characters in body
Source Link
Justin
  • 2.6k
  • 3
  • 21
  • 59
 
 
 
 
added 41 characters in body
Source Link
Justin
  • 2.6k
  • 3
  • 21
  • 59

So, overall, your code would then look like this (in terms of code readability and style) -

So, overall, your code would then look like this -

So, overall, your code would then look like this (in terms of code readability and style) -

added 41 characters in body
Source Link
Justin
  • 2.6k
  • 3
  • 21
  • 59

I believe that good code should have good style and should be more readable and concise.

some_listactivity_list = list()  
import random
import operator

def activity_selection():
    begin = [random.randint(1, 10) for i in range(10)]
    end = [x + random.randint(1, 4) for x in begin]
    pair = sorted(list(zip(begin, end)), key=operator.itemgetter(1))
    some_listactivity_list = list()
    some_listactivity_list.append(pair[0])
    for i in pair[1:]:
        if i[0] >= some_list[activity_list[-1][1]:
            some_listactivity_list.append(i)
    print(f'{some_listactivity_list} >>> {len(some_listactivity_list)} out of {len(pair)} activities.')
    # or
    # print('{} >>> {} out of {} activities.'.format(some_listactivity_list, len(some_listactivity_list), len(pair)))
    
if __name__ == '__main__':
    activity_selection()

I believe good code should have good style and should be more readable and concise.

some_list = list()  
import random
import operator

def activity_selection():
    begin = [random.randint(1, 10) for i in range(10)]
    end = [x + random.randint(1, 4) for x in begin]
    pair = sorted(list(zip(begin, end)), key=operator.itemgetter(1))
    some_list = list()
    some_list.append(pair[0])
    for i in pair[1:]:
        if i[0] >= some_list[-1][1]:
            some_list.append(i)
    print(f'{some_list} >>> {len(some_list)} out of {len(pair)} activities.')
    # or
    # print('{} >>> {} out of {} activities.'.format(some_list, len(some_list), len(pair)))
    
if __name__ == '__main__':
    activity_selection()

I believe that good code should have good style and should be more readable and concise.

activity_list = list()  
import random
import operator

def activity_selection():
    begin = [random.randint(1, 10) for i in range(10)]
    end = [x + random.randint(1, 4) for x in begin]
    pair = sorted(list(zip(begin, end)), key=operator.itemgetter(1))
    activity_list = list()
    activity_list.append(pair[0])
    for i in pair[1:]:
        if i[0] >= activity_list[-1][1]:
            activity_list.append(i)
    print(f'{activity_list} >>> {len(activity_list)} out of {len(pair)} activities.')
    # or
    # print('{} >>> {} out of {} activities.'.format(activity_list, len(activity_list), len(pair)))

if __name__ == '__main__':
    activity_selection()
added 23 characters in body
Source Link
Justin
  • 2.6k
  • 3
  • 21
  • 59
Loading
added 4 characters in body
Source Link
Justin
  • 2.6k
  • 3
  • 21
  • 59
Loading
added 213 characters in body
Source Link
Justin
  • 2.6k
  • 3
  • 21
  • 59
Loading
added 423 characters in body
Source Link
Justin
  • 2.6k
  • 3
  • 21
  • 59
Loading
added 423 characters in body
Source Link
Justin
  • 2.6k
  • 3
  • 21
  • 59
Loading
added 423 characters in body
Source Link
Justin
  • 2.6k
  • 3
  • 21
  • 59
Loading
added 292 characters in body
Source Link
Justin
  • 2.6k
  • 3
  • 21
  • 59
Loading
Source Link
Justin
  • 2.6k
  • 3
  • 21
  • 59
Loading