我有一个地址列表,如果他们是美国或加拿大,则想举报。我有美国各州和CA Providences的列表。有没有更像红宝石的方式做到这一点:
us = false
address = '1234 Fake Address Ave N, Funtown, TX, 59595'
address = address.split(' ')
address.each do |part|
if USStates.include? part
us = true
end
end
答案 0 :(得分:3)
这里是一个班轮
address = '1234 Fake Address Ave N, Funtown, TX, 59595'
us = USStates.any? { |state| address.include?(state) }
答案 1 :(得分:1)
import time
import pygame
from pygame.locals import *
# Constants
SCREEN_WIDTH = 500
SCREEN_HEIGHT= 500
white = (255,255,255)
black = (0,0,0)
# Pygame initialisation
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))
pygame.display.set_caption("AppliedShapes")
clock = pygame.time.Clock()
# rectangle that moves
move_rect = pygame.Rect( 5, 0, 50, 50 ) # define a Rect
move_x = 5 # pixels movement
move_y = 2 + move_rect.height # pixels movement
while True:
# User input
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
# Screen re-painting
screen.fill(black)
pygame.draw.rect(screen,white, move_rect ,0)
# Move the rectangle, reverse direction at the sides
if ( move_rect.left <= 0 or move_rect.right >= SCREEN_WIDTH-1 ):
# Hit the sides: move down, change direction
move_x *= -1 # change direction
move_rect.move_ip( move_x, move_y )
elif ( move_rect.bottom >= SCREEN_HEIGHT-1 ):
# Hit the bottom: move back to 0,0, continue right
move_x = abs( move_x ) # re-start going right
move_rect.topleft = ( move_x, 0 )
else:
# Didn't hit anything, just continue horizontally
move_rect.move_ip( move_x, 0 )
pygame.display.update()
clock.tick_busy_loop(60) # limit FPS to 60