Last active
March 16, 2017 06:41
-
-
Save cle-ment/9c23672aad925c49ae79b2e7849d0143 to your computer and use it in GitHub Desktop.
Find index of combination over arrays
This file contains hidden or 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
| { | |
| "cells": [ | |
| { | |
| "metadata": {}, | |
| "cell_type": "markdown", | |
| "source": "# Find index of combination over arrays:" | |
| }, | |
| { | |
| "metadata": { | |
| "trusted": true, | |
| "collapsed": false | |
| }, | |
| "cell_type": "code", | |
| "source": "search_string = '1970-01-02'\n\nsearch_year, search_month, search_day = list(map(int, search_string.split('-')))\nsearch_year, search_month, search_day", | |
| "execution_count": 14, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": "(1970, 1, 2)" | |
| }, | |
| "execution_count": 14, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ] | |
| }, | |
| { | |
| "metadata": { | |
| "trusted": true, | |
| "collapsed": false | |
| }, | |
| "cell_type": "code", | |
| "source": "data = [\n [1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970, 1970 ],\n [ 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2 ],\n [ 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 ]\n]", | |
| "execution_count": 15, | |
| "outputs": [] | |
| }, | |
| { | |
| "metadata": { | |
| "trusted": true, | |
| "collapsed": false | |
| }, | |
| "cell_type": "code", | |
| "source": "for index, (year, month, day) in enumerate(zip(*data)):\n if year == search_year and month == search_month and day == search_day:\n print(\"Index of combination is:\", index)\n break", | |
| "execution_count": 17, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "text": "Index of combination is: 6\n", | |
| "output_type": "stream" | |
| } | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "gist": { | |
| "id": "", | |
| "data": { | |
| "description": "Studio/muso/muso-crawlers/Untitled.ipynb", | |
| "public": false | |
| } | |
| }, | |
| "toc": { | |
| "toc_window_display": true, | |
| "toc_cell": false, | |
| "toc_number_sections": false, | |
| "toc_threshold": 6 | |
| }, | |
| "kernelspec": { | |
| "name": "python3", | |
| "display_name": "Python [default]", | |
| "language": "python" | |
| }, | |
| "anaconda-cloud": {}, | |
| "language_info": { | |
| "file_extension": ".py", | |
| "name": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.5.2", | |
| "mimetype": "text/x-python", | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "nbconvert_exporter": "python" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 1 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment