random.choices(['q1', 'q2', 'q3'], weights=[0.2, 0.3, 0.5])
collections.Counter( random.choices(['q1', 'q2', 'q3'], weights=[0.2, 0.3, 0.5]))[0] for _ in range(100000))
>>> collections.Counter( random.choices(['q1', 'q2', 'q3'], weights=[0.2, 0.3, 0.5]) [0] for _ in range(100000))
Counter({'q3': 49981, 'q2': 30018, 'q1': 20001})
#post_detail.html
<code lang="html">
{%extends 'home.html'%}
{%block content%}
<p> Back to <a href="{% url 'home' %}"> All Posts </a></p>
<div class="post-entry">
<h2> {{object.title}} </h2>
{% if object.image %}
<h2> <img src="{{object.image}}"></h2>
{% else %}
< p> нет изображения </p>
{% endif %}
<h2> <img src="{{object.cover.url}}"></h2>
</div>
{%endblock content%}
</code>
import pygame, pyglet, ctypes
#setup pyglet & the video
path = r"C:\SomeVideo.avi"
player = pyglet.media.Player()
source = pyglet.media.load(path)
player.queue(source)
player.play()
#setup pygame
pygame.init()
pygame.display.set_mode((800,800), 0)
pygame.display.set_caption("Video in Pygame!")
screen = pygame.display.get_surface()
pygame.display.flip()
#blit the video in a standard pygame event loop
while True:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
sys.exit(0)
screen.fill(0)
player.dispatch_events()
tex = player.get_texture()
raw = tex.get_image_data().get_data('RGBA',tex.width*4)
raw = ctypes.string_at(ctypes.addressof(raw), ctypes.sizeof(raw))
img = pygame.image.frombuffer(raw, (tex.width, tex.height), 'RGBA')
screen.blit(img, (0,0))
pygame.display.flip()
room = models.ForeignKey(Room, on_delete=models.CASCADE)