Skip to content

Instantly share code, notes, and snippets.

@adagio
Created December 19, 2018 03:49
Show Gist options
  • Save adagio/73020985104de700a7f26bdcfdb57e66 to your computer and use it in GitHub Desktop.
Save adagio/73020985104de700a7f26bdcfdb57e66 to your computer and use it in GitHub Desktop.
First Ocurrence
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"ocurrence = None"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"7\n",
"14\n",
"21\n",
"28\n"
]
}
],
"source": [
"for i in range(1,30):\n",
" if i % 7 == 0:\n",
" print(i)\n",
" ocurrence = ocurrence or i"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ocurrence"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"None or 7"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"7 or 14"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Truth Value](https://docs.python.org/3/library/stdtypes.html#truth-value-testing)\n",
"\n",
"**x or y**: if x is false, then y, else x"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment