This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
import random | |
current = set(string.digits+string.letters) | |
for i in range(6): | |
sample = random.sample(current,5) | |
current = current - set(sample) | |
print sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for v in lista: | |
if lista[v] == idb: | |
lista[v] = ida | |
[a==5 and "change" or a for a in range(10)] | |
[0, 1, 2, 3, 4, 'change', 6, 7, 8, 9] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f = open("numeros_mobile.txt") | |
data = {} | |
for f in f.readlines(): | |
k,v = f.strip("\n").split("\t") | |
data[k]=v | |
import random | |
winner = False | |
while not winner: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr = [1,-1,4,2,1,5,-2] | |
negs = [] | |
for i in arr: | |
if i<0: | |
negs.append(arr.remove(i)) | |
if negs: | |
raise ValueError(negs) | |
else: | |
print sum(arr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Es par o impar") | |
numero = int(raw_input("introducir un numero")) #utiliza raw_input, ya que input puede traer codigo ejecutable http://stackoverflow.com/questions/3800846/differences-between-input-and-raw-input | |
if numero%2: #en python el if evalua directo so == 0 es inneesario | |
print ("El numero ingresado es par") #usa los parentesis simple, ya que en py3 no son opcionales | |
else: | |
print ("El numero ingresado es impar") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> str1 = 'There are two types of people in the world' | |
>>> str2 = 'Hello my name is caonabo welcome to dominican republic' | |
>>> str2.split(' ') | |
['Hello', 'my', 'name', 'is', 'caonabo', 'welcome', 'to', 'dominican', 'republic'] | |
# El default de split es ASCII 32 so | |
>>> str2.split() | |
['Hello', 'my', 'name', 'is', 'caonabo', 'welcome', 'to', 'dominican', 'republic'] | |
#no te compliques con chr | |
>>> [s for s in str1.split() if s[0] == 'w'] | |
['world'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ical = require('ical'); | |
var http = require('http'); | |
var express = require('express'); | |
var app = express(); | |
var json = []; | |
ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function(err, data) { | |
json = data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rock-paper-scissors-lizard-Spock template | |
# The key idea of this program is to equate the strings | |
# "rock", "paper", "scissors", "lizard", "Spock" to numbers | |
# as follows: | |
# | |
# 0 - rock | |
# 1 - Spock | |
# 2 - paper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Signal(object): | |
def __init__(self,providing_args): | |
pass | |
signals = {'hook': [Signal(providing_args=a) for a in ['change','...']]} | |
#output is | |
# {'hook': [<__main__.Signal object at 0x10334dcd0>, <__main__.Signal object at 0x10334dd10>]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
def initialize() | |
@health = 21 | |
@forward = :forward | |
@backward = :backward | |
@direction = @forward | |
end | |
def play_turn(warrior) | |
spaces = warrior.look(:forward) |
NewerOlder