Skip to content

Instantly share code, notes, and snippets.

View jamesmcnamara's full-sized avatar

James McNamara jamesmcnamara

View GitHub Profile
def sum67(nums):
return sum(map(lambda inums: reduce(lambda acc, (x, y): acc + sum(x), [(list(takewhile(lambda x: x != 6, inums)), list(takewhile(lambda x: x != 7, inums))) for _ in range(nums.count(6) + 1)],0) if nums.count(6) else sum(nums), [iter(nums)]))
@jamesmcnamara
jamesmcnamara / rest_skeleton.py
Last active March 8, 2016 05:03
Rest Skeleton
from operator import attrgetter
import os
from django.db.models import Model
from django.core.management.base import BaseCommand
from rest_framework.serializers import ModelSerializer
from rest_framework.viewsets import ModelViewSet
from my_app import serializers, models, views
from math import log, floor, ceil
is_odd = lambda n: n % 2
is_even = lambda n: not is_odd(n)
log2 = lambda n: log(n, 2)
is_power_of_2 = lambda n: log2(n) == int(log2(n))
def find_number_of_steps(n):
if is_power_of_2(n):
from timeit import timeit
random_list = '''
from random import randint
l = [randint(0, 1000) for _ in range(1000000)]
value = 50
'''
loop = '''