diff --git "a/notebook/LeetCode/-0005-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.ipynb" "b/notebook/LeetCode/-0005-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.ipynb" new file mode 100644 index 0000000..a3d3929 --- /dev/null +++ "b/notebook/LeetCode/-0005-\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.ipynb" @@ -0,0 +1,57 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:中等\n", + "\n", + "知识点:字符串、动态规划\n", + "\n", + "地址:[https://leetcode-cn.com/problems/longest-palindromic-substring/](https://leetcode-cn.com/problems/longest-palindromic-substring/)\n", + "\n", + "\n", + "给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。\n", + "\n", + "示例 1:\n", + "\n", + " 输入: \"babad\"\n", + " 输出: \"bab\"\n", + " 注意: \"aba\" 也是一个有效答案。\n", + " \n", + "示例 2:\n", + "\n", + " 输入: \"cbbd\"\n", + " 输出: \"bb\"\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/-0008-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).ipynb" "b/notebook/LeetCode/-0008-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).ipynb" new file mode 100644 index 0000000..8c6c5c7 --- /dev/null +++ "b/notebook/LeetCode/-0008-\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\225\264\346\225\260(atoi).ipynb" @@ -0,0 +1,130 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:中等\n", + "\n", + "知识点:数学、字符串\n", + "\n", + "地址:[https://leetcode-cn.com/problems/string-to-integer-atoi/](https://leetcode-cn.com/problems/string-to-integer-atoi/)\n", + "\n", + "\n", + "请你来实现一个 atoi 函数,使其能将字符串转换成整数。\n", + "\n", + "首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止。\n", + "\n", + "当我们寻找到的第一个非空字符为正或者负号时,则将该符号与之后面尽可能多的连续数字组合起来,作为该整数的正负号;假如第一个非空字符是数字,则直接将其与之后连续的数字字符组合起来,形成整数。\n", + "\n", + "该字符串除了有效的整数部分之后也可能会存在多余的字符,这些字符可以被忽略,它们对于函数不应该造成影响。\n", + "\n", + "注意:\n", + " \n", + " 假如该字符串中的第一个非空格字符不是一个有效整数字符、字符串为空或字符串仅包含空白字符时,则你的函数不需要进行转换。\n", + " 在任何情况下,若函数不能进行有效的转换时,请返回 0。\n", + "\n", + "说明:\n", + "\n", + " 假设我们的环境只能存储 32 位大小的有符号整数,那么其数值范围为 [−2^31, 2^31 − 1]。如果数值超过这个范围,qing返回 INT_MAX (231 − 1) 或 INT_MIN (−231) 。\n", + "\n", + "示例 1:\n", + "\n", + " 输入: \"42\"\n", + " 输出: 42\n", + "\n", + "示例 2:\n", + "\n", + " 输入: \" -42\"\n", + " 输出: -42\n", + " 解释: 第一个非空白字符为 '-', 它是一个负号。\n", + " 我们尽可能将负号与后面所有连续出现的数字组合起来,最后得到 -42 。\n", + "\n", + "示例 3:\n", + "\n", + " 输入: \"4193 with words\"\n", + " 输出: 4193\n", + " 解释: 转换截止于数字 '3' ,因为它的下一个字符不为数字。\n", + "\n", + "示例 4:\n", + "\n", + " 输入: \"words and 987\"\n", + " 输出: 0\n", + " 解释: 第一个非空字符是 'w', 但它不是数字或正、负号。\n", + " 因此无法执行有效的转换。\n", + "\n", + "示例 5:\n", + "\n", + " 输入: \"-91283472332\"\n", + " 输出: -2147483648\n", + " 解释: 数字 \"-91283472332\" 超过 32 位有符号整数范围。\n", + " 因此返回 INT_MIN (−2^31) 。\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "ename": "AssertionError", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmyAtoi\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\" -42\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m-\u001b[0m\u001b[0;36m42\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmyAtoi\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"4193 with words\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m4193\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 36\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmyAtoi\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"words and 987\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m42\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 37\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmyAtoi\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"-91283472332\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mMIN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mAssertionError\u001b[0m: " + ] + } + ], + "source": [ + "from config import MAX\n", + "from config import MIN\n", + "\n", + "NUMS = {\"1\", \"2\", '3', '4', '5', '6', '7', '8', '9', '0'}\n", + "INTS = {\"1\", \"2\", '3', '4', '5', '6', '7', '8', '9'}\n", + "class Solution:\n", + " def myAtoi(self, s: str) -> int:\n", + " \n", + " singal = 1\n", + " ans = 0\n", + " for a in s:\n", + " if a == ' ':\n", + " continue\n", + " if ans == 0 and a not in INTS:\n", + " \n", + " \n", + " return ans\n", + "\n", + "s = Solution()\n", + "assert s.myAtoi(\"42\") == 42\n", + "assert s.myAtoi(\" -42\") == -42\n", + "assert s.myAtoi(\"4193 with words\") == 4193\n", + "assert s.myAtoi(\"words and 987\") == 42\n", + "assert s.myAtoi(\"-91283472332\") == MIN" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/-0014-\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.ipynb" "b/notebook/LeetCode/-0014-\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.ipynb" new file mode 100644 index 0000000..9967309 --- /dev/null +++ "b/notebook/LeetCode/-0014-\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.ipynb" @@ -0,0 +1,81 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:简单\n", + "\n", + "知识点:字符串\n", + "\n", + "地址:[https://leetcode-cn.com/problems/longest-common-prefix/](https://leetcode-cn.com/problems/longest-common-prefix/)\n", + "\n", + "\n", + "编写一个函数来查找字符串数组中的最长公共前缀。\n", + "\n", + "如果不存在公共前缀,返回空字符串 \"\"。\n", + "\n", + "示例 1:\n", + "\n", + " 输入: [\"flower\",\"flow\",\"flight\"]\n", + " 输出: \"fl\"\n", + "示例 2:\n", + "\n", + " 输入: [\"dog\",\"racecar\",\"car\"]\n", + " 输出: \"\"\n", + " 解释: 输入不存在公共前缀。\n", + "说明:\n", + "\n", + " 所有输入只包含小写字母 a-z 。\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "class Solution:\n", + " def longestCommonPrefix(self, strs) -> str:\n", + " strs.sort(key = lambda x: len(x))\n", + " res = strs[0]\n", + " i = len(res)\n", + " while i >= 0:\n", + " for s in strs[1:]:\n", + " if not s.startswith(res[:i]):\n", + " i -= 1\n", + " break\n", + " if i < 0:\n", + " return ''\n", + " return res[:i]\n", + " \n", + " \n", + "\n", + "s = Solution()\n", + "assert s.longestCommonPrefix([\"flower\",\"flow\",\"flight\"]) == 'fl'\n", + "assert s.longestCommonPrefix([\"dog\",\"racecar\",\"car\"]) == ''" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/0001-\344\270\244\346\225\260\344\271\213\345\222\214.ipynb" "b/notebook/LeetCode/0001-\344\270\244\346\225\260\344\271\213\345\222\214.ipynb" new file mode 100644 index 0000000..574cc25 --- /dev/null +++ "b/notebook/LeetCode/0001-\344\270\244\346\225\260\344\271\213\345\222\214.ipynb" @@ -0,0 +1,121 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:简单\n", + "\n", + "地址:[https://leetcode-cn.com/problems/two-sum/](https://leetcode-cn.com/problems/two-sum/)\n", + "\n", + "给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。\n", + "\n", + "你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。\n", + "\n", + "示例:\n", + "\n", + " 给定 nums = [2, 7, 11, 15], target = 9\n", + " 因为 nums[0] + nums[1] = 2 + 7 = 9\n", + " 所以返回 [0, 1]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 1]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "class Solution:\n", + " def twoSum(self, nums, target):\n", + " '''\n", + " 两遍哈希表 时间复杂度 O(n)\n", + " 执行用时 : 56 ms, 在Two Sum的Python3提交中击败了89.57% 的用户\n", + " 内存消耗 : 14.7 MB, 在Two Sum的Python3提交中击败了7.13% 的用户\n", + " '''\n", + " length = len(nums)\n", + " m = {}\n", + " for i in range(length):\n", + " m[nums[i]] = i\n", + " for i in range(length):\n", + " x = nums[i]\n", + " y = target - x\n", + " if y in m:\n", + " return [i, m[y]]\n", + " \n", + " \n", + "\n", + "s = Solution()\n", + "s.twoSum([2, 7, 11, 15], 9)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 1]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "class Solution:\n", + " def twoSum(self, nums, target):\n", + " '''\n", + " 一遍哈希表 时间复杂度 O(n)\n", + " 执行用时 : 44 ms, 在Two Sum的Python3提交中击败了99.33% 的用户\n", + " 内存消耗 : 14 MB, 在Two Sum的Python3提交中击败了56.25% 的用户\n", + " '''\n", + " m = {}\n", + " for i in range(len(nums)):\n", + " x = nums[i]\n", + " y = target - x\n", + " if y in m:\n", + " return [m[y], i]\n", + " m[x] = i\n", + " \n", + "\n", + "s = Solution()\n", + "s.twoSum([2, 7, 11, 15], 9)" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/0002-\344\270\244\346\225\260\347\233\270\345\212\240.ipynb" "b/notebook/LeetCode/0002-\344\270\244\346\225\260\347\233\270\345\212\240.ipynb" new file mode 100644 index 0000000..8d0fcd5 --- /dev/null +++ "b/notebook/LeetCode/0002-\344\270\244\346\225\260\347\233\270\345\212\240.ipynb" @@ -0,0 +1,89 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:中等\n", + "\n", + "知识点:链表、数学\n", + "\n", + "地址: [https://leetcode-cn.com/problems/add-two-numbers/](https://leetcode-cn.com/problems/add-two-numbers/)\n", + "\n", + "\n", + "给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。\n", + "\n", + "如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。\n", + "\n", + "您可以假设除了数字 0 之外,这两个数都不会以 0 开头。\n", + "\n", + "示例:\n", + "\n", + " 输入:(2 -> 4 -> 3) + (5 -> 6 -> 4)\n", + " 输出:7 -> 0 -> 8\n", + " 原因:342 + 465 = 807\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "from utils import ListNode\n", + "from utils import array2listnode\n", + "from utils import listnode2array\n", + "\n", + "class Solution:\n", + " def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:\n", + " '''\n", + " 一遍循环\n", + " 执行用时 : 88 ms, 在Add Two Numbers的Python3提交中击败了99.56% 的用户\n", + " 内存消耗 : 13.1 MB, 在Add Two Numbers的Python3提交中击败了90.86% 的用户\n", + " '''\n", + " rem = 0 # 余数\n", + " l3 = ListNode(0)\n", + " l4 = l3\n", + " while l1 or l2 or rem:\n", + " n3 = rem\n", + " if l1:\n", + " n3 += l1.val\n", + " l1 = l1.next\n", + " if l2:\n", + " n3 += l2.val\n", + " l2 = l2.next\n", + " rem = n3 // 10\n", + " l4.next = ListNode(n3 % 10)\n", + " l4 = l4.next\n", + " return l3.next\n", + " \n", + " \n", + " \n", + "s = Solution()\n", + "assert listnode2array(s.addTwoNumbers(array2listnode([2, 4, 3]), array2listnode([5, 6, 4]))) == [7, 0, 8]\n", + "# assert 1 ==1\n" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/0003-\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.ipynb" "b/notebook/LeetCode/0003-\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.ipynb" new file mode 100644 index 0000000..86267d3 --- /dev/null +++ "b/notebook/LeetCode/0003-\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.ipynb" @@ -0,0 +1,92 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:中等\n", + "\n", + "知识点:哈希表、双指针、字符串、Sliding Window\n", + "\n", + "地址: [https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/)\n", + "\n", + "\n", + "给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。\n", + "\n", + "示例 1:\n", + "\n", + " 输入: \"abcabcbb\"\n", + " 输出: 3\n", + " 解释: 因为无重复字符的最长子串是 \"abc\",所以其长度为 3。\n", + "\n", + "示例 2:\n", + "\n", + " 输入: \"bbbbb\"\n", + " 输出: 1\n", + " 解释: 因为无重复字符的最长子串是 \"b\",所以其长度为 1。\n", + "\n", + "示例 3:\n", + "\n", + " 输入: \"pwwkew\"\n", + " 输出: 3\n", + " 解释: 因为无重复字符的最长子串是 \"wke\",所以其长度为 3。\n", + " 请注意,你的答案必须是 子串 的长度,\"pwke\" 是一个子序列,不是子串。\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "class Solution:\n", + " def lengthOfLongestSubstring(self, s: str) -> int:\n", + " '''\n", + " 滑动窗口 降低代码复杂度\n", + " 时间复杂度 O(n)\n", + " 空间复杂度 O(n)\n", + " \n", + " 执行用时 : 100 ms, 在Longest Substring Without Repeating Characters的Python3提交中击败了80.66% 的用户\n", + " 内存消耗 : 13.1 MB, 在Longest Substring Without Repeating Characters的Python3提交中击败了85.21% 的用户\n", + " '''\n", + " ans, i= 0, 0\n", + " m = {}\n", + " for j in range(len(s)):\n", + " n = s[j]\n", + " if n in m:\n", + " i = max(i, m[n] + 1)\n", + " ans = max(ans, j - i + 1)\n", + " m[n] = j\n", + " \n", + " return ans\n", + "\n", + " \n", + "s = Solution()\n", + "assert s.lengthOfLongestSubstring(\"abcabcbb\") == 3\n", + "assert s.lengthOfLongestSubstring(\"bbbbb\") == 1\n", + "assert s.lengthOfLongestSubstring(\"pwwkew\") == 3" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/0004-\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.ipynb" "b/notebook/LeetCode/0004-\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.ipynb" new file mode 100644 index 0000000..62b2b11 --- /dev/null +++ "b/notebook/LeetCode/0004-\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.ipynb" @@ -0,0 +1,103 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:困难\n", + "\n", + "知识点:数组、二分查找、分治算法\n", + "\n", + "地址: [https://leetcode-cn.com/problems/median-of-two-sorted-arrays/](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/)\n", + "\n", + "\n", + "给定两个大小为 m 和 n 的有序数组 nums1 和 nums2。\n", + "\n", + "请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n))。\n", + "\n", + "你可以假设 nums1 和 nums2 不会同时为空。\n", + "\n", + "示例 1:\n", + "\n", + " nums1 = [1, 3]\n", + " nums2 = [2]\n", + "\n", + " 则中位数是 2.0\n", + "\n", + "示例 2:\n", + "\n", + " nums1 = [1, 2]\n", + " nums2 = [3, 4]\n", + "\n", + " 则中位数是 (2 + 3)/2 = 2.5\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "class Solution:\n", + "\n", + " def findMedianSortedArrays(self, nums1: list, nums2: list) -> float:\n", + " '''\n", + " 执行用时 : 104 ms, 在Median of Two Sorted Arrays的Python3提交中击败了62.78% 的用户\n", + " 内存消耗 : 13.4 MB, 在Median of Two Sorted Arrays的Python3提交中击败了47.77% 的用户\n", + " \n", + " 因为是有序列表,同时按照索引比较两个数组的数,重组一个有序的新列表,长度大的列表比较剩下的部分可以直接拼接到新数组中\n", + " '''\n", + "\n", + " nums = []\n", + " i, j = 0, 0\n", + " while i < len(nums1) and j < len(nums2):\n", + " x = nums1[i]\n", + " y = nums2[j]\n", + " if x < y:\n", + " nums.append(x)\n", + " i += 1\n", + " else:\n", + " nums.append(y)\n", + " j += 1\n", + " if i < len(nums1) and j >= len(nums2):\n", + " nums.extend(nums1[i:])\n", + " elif i >= len(nums1) and j < len(nums2):\n", + " nums.extend(nums2[j:])\n", + " \n", + " if len(nums) % 2:\n", + " return nums[len(nums) // 2]\n", + " else:\n", + " mid = len(nums) // 2\n", + " return (nums[mid] + nums[mid - 1]) / 2\n", + " \n", + "\n", + " \n", + "s = Solution()\n", + "assert s.findMedianSortedArrays([1, 3], [2]) == 2.0\n", + "assert s.findMedianSortedArrays([1, 2], [3, 4]) == 2.5" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/0007-\346\225\264\346\225\260\345\217\215\350\275\254.ipynb" "b/notebook/LeetCode/0007-\346\225\264\346\225\260\345\217\215\350\275\254.ipynb" new file mode 100644 index 0000000..cd2383b --- /dev/null +++ "b/notebook/LeetCode/0007-\346\225\264\346\225\260\345\217\215\350\275\254.ipynb" @@ -0,0 +1,95 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:简单\n", + "\n", + "知识点:数学\n", + "\n", + "地址:[https://leetcode-cn.com/problems/reverse-integer/](https://leetcode-cn.com/problems/reverse-integer/)\n", + "\n", + "给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。\n", + "\n", + "示例 1:\n", + "\n", + " 输入: 123\n", + " 输出: 321\n", + "示例 2:\n", + "\n", + " 输入: -123\n", + " 输出: -321\n", + "示例 3:\n", + "\n", + " 输入: 120\n", + " 输出: 21\n", + "注意:\n", + "\n", + " 假设我们的环境只能存储得下 32 位的有符号整数,则其数值范围为 [−2^31, 2^31 − 1]。请根据这个假设,如果反转后整数溢出那么就返回 0。\n", + " 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "from config import MAX\n", + "from config import MIN\n", + "class Solution:\n", + "\n", + "\n", + "\n", + " def reverse(self, x: int) -> int:\n", + " '''\n", + " 弹出和推入数字\n", + " 时间复杂度 O(logn)\n", + " 空间复杂度 O(1)\n", + " 执行用时 : 48 ms, 在Reverse Integer的Python3提交中击败了98.06% 的用户\n", + " 内存消耗 : 13 MB, 在Reverse Integer的Python3提交中击败了99.21% 的用户 \n", + " '''\n", + " ans = 0\n", + " rem = 10 if x > 0 else -10\n", + " while x != 0:\n", + " yu = x % rem\n", + " ans = ans * 10 + yu\n", + " x //= 10\n", + " if x < 0 and yu != 0:\n", + " x += 1\n", + " \n", + " if ans > MAX or ans < MIN:\n", + " return 0\n", + " return ans\n", + "\n", + "s = Solution()\n", + "assert s.reverse(-123) == -321\n", + "assert s.reverse(123) == 321\n", + "assert s.reverse(120) == 21\n", + "\n" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/0009-\345\233\236\346\226\207\346\225\260.ipynb" "b/notebook/LeetCode/0009-\345\233\236\346\226\207\346\225\260.ipynb" new file mode 100644 index 0000000..170a8a0 --- /dev/null +++ "b/notebook/LeetCode/0009-\345\233\236\346\226\207\346\225\260.ipynb" @@ -0,0 +1,144 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:简单\n", + "\n", + "知识点:数学\n", + "\n", + "地址:[https://leetcode-cn.com/problems/palindrome-number/](https://leetcode-cn.com/problems/palindrome-number/)\n", + "\n", + "判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。\n", + "\n", + "示例 1:\n", + "\n", + " 输入: 121\n", + " 输出: true\n", + "示例 2:\n", + "\n", + " 输入: -121\n", + " 输出: false\n", + " 解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。\n", + "示例 3:\n", + "\n", + " 输入: 10\n", + " 输出: false\n", + " 解释: 从右向左读, 为 01 。因此它不是一个回文数。\n", + "进阶:\n", + "\n", + " 你能不将整数转为字符串来解决这个问题吗?\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 思路1:数字取余\n", + "\n", + "- 数字小于 0 时直接返回 False\n", + "- 数字等于 0 时直接返回 True\n", + "- 利用取余的方式将数字反转、最后跟原数字对比,如果相同则返回 True\n", + " - 取余的过程中如果原数字能被 10 整除,则返回 False" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "class Solution:\n", + " def isPalindrome(self, x: int) -> bool:\n", + " '''\n", + " 执行用时: 96 ms , 在所有 Python3 提交中击败了 40.97% 的用户\n", + " 内存消耗: 13.7 MB , 在所有 Python3 提交中击败了 5.88% 的用户\n", + " '''\n", + " if x < 0:\n", + " return False\n", + " if x == 0:\n", + " return True\n", + " ans, y = 0, x\n", + " while y != 0:\n", + " div = y % 10\n", + " if div == 0 and ans == 0:\n", + " return False\n", + " ans = ans * 10 + div\n", + " y //=10\n", + " if ans == x:\n", + " return True\n", + " return False\n", + "\n", + "s = Solution()\n", + "assert s.isPalindrome(121) == True\n", + "assert s.isPalindrome(-121) == False\n", + "assert s.isPalindrome(10) == False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 思路2:字符串比较\n", + "\n", + "- 数字小于 0 时直接返回 False\n", + "- 数字等于 0 时直接返回 True\n", + "- 将数字转为字符串,利用滑块,从两端向中间靠拢,首尾字符进行比较,如果返现不一致,则返回 False" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "class Solution:\n", + " def isPalindrome(self, x: int) -> bool:\n", + " '''\n", + " 执行用时: 88 ms , 在所有 Python3 提交中击败了 60.64% 的用户\n", + " 内存消耗: 13.7 MB , 在所有 Python3 提交中击败了 5.88% 的用户\n", + " '''\n", + " if x < 0:\n", + " return False\n", + " if x == 0:\n", + " return True\n", + " s = str(x)\n", + " i, j = 0, len(s) - 1\n", + " while i < j:\n", + " if s[i] != s[j]:\n", + " return False\n", + " i += 1\n", + " j -= 1\n", + " return True\n", + "\n", + "s = Solution()\n", + "assert s.isPalindrome(121) == True\n", + "assert s.isPalindrome(-121) == False\n", + "assert s.isPalindrome(10) == False" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/0013-\347\275\227\351\251\254\346\225\260\345\255\227\350\275\254\346\225\264\346\225\260.ipynb" "b/notebook/LeetCode/0013-\347\275\227\351\251\254\346\225\260\345\255\227\350\275\254\346\225\264\346\225\260.ipynb" new file mode 100644 index 0000000..d24b25a --- /dev/null +++ "b/notebook/LeetCode/0013-\347\275\227\351\251\254\346\225\260\345\255\227\350\275\254\346\225\264\346\225\260.ipynb" @@ -0,0 +1,138 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:简单\n", + "\n", + "知识点:数学、字符串\n", + "\n", + "地址:[https://leetcode-cn.com/problems/roman-to-integer/](https://leetcode-cn.com/problems/roman-to-integer/)\n", + "\n", + "\n", + "罗马数字包含以下七种字符: I, V, X, L,C,D 和 M。\n", + "\n", + " 字符 数值\n", + " I 1\n", + " V 5\n", + " X 10\n", + " L 50\n", + " C 100\n", + " D 500\n", + " M 1000\n", + "例如, 罗马数字 2 写做 II ,即为两个并列的 1。12 写做 XII ,即为 X + II 。 27 写做  XXVII, 即为 XX + V + II 。\n", + "\n", + "通常情况下,罗马数字中小的数字在大的数字的右边。但也存在特例,例如 4 不写做 IIII,而是 IV。数字 1 在数字 5 的左边,所表示的数等于大数 5 减小数 1 得到的数值 4 。同样地,数字 9 表示为 IX。这个特殊的规则只适用于以下六种情况:\n", + "\n", + "- I 可以放在 V (5) 和 X (10) 的左边,来表示 4 和 9。\n", + "- X 可以放在 L (50) 和 C (100) 的左边,来表示 40 和 90。 \n", + "- C 可以放在 D (500) 和 M (1000) 的左边,来表示 400 和 900。\n", + "\n", + "给定一个罗马数字,将其转换成整数。输入确保在 1 到 3999 的范围内。\n", + "\n", + "示例 1:\n", + "\n", + " 输入: \"III\"\n", + " 输出: 3\n", + "示例 2:\n", + "\n", + " 输入: \"IV\"\n", + " 输出: 4\n", + "示例 3:\n", + "\n", + " 输入: \"IX\"\n", + " 输出: 9\n", + "示例 4:\n", + "\n", + " 输入: \"LVIII\"\n", + " 输出: 58\n", + " 解释: L = 50, V= 5, III = 3.\n", + "示例 5:\n", + "\n", + " 输入: \"MCMXCIV\"\n", + " 输出: 1994\n", + " 解释: M = 1000, CM = 900, XC = 90, IV = 4.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 思路\n", + "\n", + "利用罗马数字的原理,从右向左滑动,如果左边的数字小于右边的数字,则相加,反之则相减" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "ROMAN_TO_INT = {\n", + " \"I\": 1,\n", + " \"V\": 5,\n", + " \"X\": 10,\n", + " \"L\": 50,\n", + " \"C\": 100,\n", + " \"D\": 500,\n", + " \"M\": 1000,\n", + "}\n", + "\n", + "\n", + "class Solution:\n", + " def romanToInt(self, s: str) -> int:\n", + " '''\n", + " 执行用时: 56 ms , 在所有 Python3 提交中击败了 84.47% 的用户\n", + " 内存消耗: 13.7 MB , 在所有 Python3 提交中击败了 6.45% 的用户\n", + " '''\n", + " i = len(s) - 1\n", + " ans = 0\n", + " while i >= 0:\n", + " xi = ROMAN_TO_INT[s[i]]\n", + " if i == 0:\n", + " ans += xi\n", + " break\n", + " xj = ROMAN_TO_INT[s[i - 1]]\n", + " if xi <= xj:\n", + " ans += xi\n", + " else:\n", + " ans += xi - xj\n", + " i -= 1\n", + " \n", + " i -= 1\n", + " \n", + " return ans\n", + "\n", + "s = Solution()\n", + "assert s.romanToInt('III') == 3\n", + "assert s.romanToInt('IV') == 4\n", + "assert s.romanToInt('IX') == 9\n", + "assert s.romanToInt('LVIII') == 58\n", + "assert s.romanToInt('MCMXCIV') == 1994\n" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/0020-\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267.ipynb" "b/notebook/LeetCode/0020-\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267.ipynb" new file mode 100644 index 0000000..7671fd4 --- /dev/null +++ "b/notebook/LeetCode/0020-\346\234\211\346\225\210\347\232\204\346\213\254\345\217\267.ipynb" @@ -0,0 +1,132 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:简单\n", + "\n", + "知识点:栈、字符串\n", + "\n", + "地址:https://leetcode-cn.com/problems/valid-parentheses/\n", + "\n", + "给定一个只包括 `'(',')','{','}','[',']'` 的字符串,判断字符串是否有效。\n", + "\n", + "有效字符串需满足:\n", + "\n", + " 左括号必须用相同类型的右括号闭合。\n", + " 左括号必须以正确的顺序闭合。\n", + " 注意空字符串可被认为是有效字符串。\n", + "\n", + "示例 1:\n", + "\n", + " 输入: \"()\"\n", + " 输出: true\n", + "示例 2:\n", + "\n", + " 输入: \"()[]{}\"\n", + " 输出: true\n", + "示例 3:\n", + "\n", + " 输入: \"(]\"\n", + " 输出: false\n", + "示例 4:\n", + "\n", + " 输入: \"([)]\"\n", + " 输出: false\n", + "示例 5:\n", + "\n", + " 输入: \"{[]}\"\n", + " 输出: true\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 思路\n", + "- 通过题目我们可以得到一个结论,将字符串从左到右依次遍历,第一次遇到右括号时,一定会和最后遇到的左括号成一对。\n", + "- 将凑成一对的括号消除掉,继续向下遍历,并重复这个操作,最后将全部消除掉。\n", + "- 在这个过程中一下情况都可以返回 false,没有则可以返回 true\n", + " - 当遇到右括号时,还没有遇到左括号\n", + " - 当遇到右括号时,最后遇到的左括号不能凑成一对\n", + " - 当遇到的右括号都凑对消除后,仍然有左括号残留" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "BRACKETS = {\n", + " \")\": \"(\",\n", + " \"}\": \"{\",\n", + " \"]\": \"[\",\n", + "}\n", + "\n", + "class Solution:\n", + " def isValid(self, s):\n", + " '''\n", + " 按照解题思路,准备一个队列 stack\n", + " 1、遇到右括号时,推入到 stack 中\n", + " 2、遇到右括号时\n", + " 如果 stack 为空,则返回 False\n", + " 如果 stack 队尾不能和左括号凑成对,则返回 False\n", + " 如果 stack 队尾能和左括号凑成对,则将队尾弹出\n", + " 3、最后判断 stack 是否清空,如果没有清空,则返回 False\n", + " 执行用时: 44 ms , 在所有 Python3 提交中击败了 55.70% 的用户\n", + " 内存消耗: 13.7 MB , 在所有 Python3 提交中击败了 5.22% 的用户\n", + "\n", + " '''\n", + " stack = []\n", + " for c in s:\n", + " if c not in BRACKETS:\n", + " # 遇到的是左括号,加入到队列中\n", + " stack.append(c)\n", + " continue\n", + " \n", + " br = BRACKETS[c] # 获取左括号\n", + " if not stack:\n", + " # 如果 stack 为空,则返回 False\n", + " return False\n", + " if stack[-1] != br:\n", + " # 如果 stack 队尾不能和左括号凑成对,则返回 False\n", + " return False\n", + " # 如果 stack 队尾能和左括号凑成对,则将队尾弹出\n", + " stack.pop()\n", + " # 最后判断 stack 是否清空,如果没有清空,则返回 False\n", + " return stack == []\n", + "\n", + "s = Solution()\n", + "assert s.isValid('()') == True\n", + "assert s.isValid('()[]{}') == True\n", + "assert s.isValid('(]') == False\n", + "assert s.isValid('([)]') == False\n", + "assert s.isValid('{[]}') == True\n", + "\n" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/0021-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250.ipynb" "b/notebook/LeetCode/0021-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250.ipynb" new file mode 100644 index 0000000..c52c6b4 --- /dev/null +++ "b/notebook/LeetCode/0021-\345\220\210\345\271\266\344\270\244\344\270\252\346\234\211\345\272\217\351\223\276\350\241\250.ipynb" @@ -0,0 +1,91 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:简单\n", + "\n", + "知识点:链表\n", + "\n", + "地址:https://leetcode-cn.com/problems/merge-two-sorted-lists\n", + "\n", + "将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 \n", + "\n", + "示例:\n", + "\n", + " 输入:1->2->4, 1->3->4\n", + " 输出:1->1->2->3->4->4\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 思路\n", + "- 因为两个链表都是升序的,所以我们可以同时遍历两个链表,并一一对比,将较小的值依次添加到新链表中\n", + "- 最后将没有遍历完的链表直接添加到新链表后面即可" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "from utils import ListNode\n", + "from utils import array2listnode\n", + "from utils import listnode2array\n", + "\n", + "class Solution:\n", + " def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:\n", + " l3 = ListNode(0)\n", + " l4 = l3\n", + " while l1 and l2:\n", + " val1 = l1.val\n", + " val2 = l2.val\n", + " if val1 <= val2:\n", + " l4.next = ListNode(val1)\n", + " l1 = l1.next\n", + " elif val1 > val2:\n", + " l4.next = ListNode(val2)\n", + " l2 = l2.next\n", + " l4 = l4.next\n", + " \n", + " if l1:\n", + " l4.next = l1\n", + " if l2:\n", + " l4.next = l2\n", + " return l3.next\n", + " \n", + " \n", + " \n", + "s = Solution()\n", + "l1 = array2listnode([1, 2, 4])\n", + "l2 = array2listnode([1, 3, 4])\n", + "assert listnode2array(s.mergeTwoLists(l1, l2)) == [1, 1, 2, 3, 4, 4]" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/0026-\345\210\240\351\231\244\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271.ipynb" "b/notebook/LeetCode/0026-\345\210\240\351\231\244\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271.ipynb" new file mode 100644 index 0000000..bccddd5 --- /dev/null +++ "b/notebook/LeetCode/0026-\345\210\240\351\231\244\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\351\207\215\345\244\215\351\241\271.ipynb" @@ -0,0 +1,115 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:简单\n", + "\n", + "知识点:数组、双指针\n", + "\n", + "地址:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array\n", + "\n", + "给定一个排序数组,你需要在 原地 删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。\n", + "\n", + "不要使用额外的数组空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下完成。\n", + "\n", + " \n", + "示例 1:\n", + "\n", + " 给定数组 nums = [1,1,2], \n", + "\n", + " 函数应该返回新的长度 2, 并且原数组 nums 的前两个元素被修改为 1, 2。 \n", + "\n", + " 你不需要考虑数组中超出新长度后面的元素。\n", + "示例 2:\n", + "\n", + " 给定 nums = [0,0,1,1,1,2,2,3,3,4],\n", + "\n", + " 函数应该返回新的长度 5, 并且原数组 nums 的前五个元素被修改为 0, 1, 2, 3, 4。\n", + "\n", + " 你不需要考虑数组中超出新长度后面的元素。\n", + " \n", + "\n", + "说明:\n", + "\n", + " 为什么返回数值是整数,但输出的答案是数组呢?\n", + "\n", + " 请注意,输入数组是以「引用」方式传递的,这意味着在函数里修改输入数组对于调用者是可见的。\n", + "\n", + " 你可以想象内部操作如下:\n", + "\n", + " // nums 是以“引用”方式传递的。也就是说,不对实参做任何拷贝\n", + " int len = removeDuplicates(nums);\n", + "\n", + " // 在函数里修改输入数组对于调用者是可见的。\n", + " // 根据你的函数返回的长度, 它会打印出数组中该长度范围内的所有元素。\n", + " for (int i = 0; i < len; i++) {\n", + " print(nums[i]);\n", + " }\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 思路\n", + "- 根据题目我们首先可以明确一个重要的条件,就是不需要考虑数组中超出新长度后面的元素,也就是说只需要把不重复的数字替换到前面即可\n", + "- 这里可以使用双指针(i, j)来比较数组, `i = 0, j= 1` 作为起始\n", + "- 比较 `nums[i] == nums[j]`,如果成立,则将 `j` 向右移动一位。如果不成立,则将 `nums[j]` 替换到 `nums[i + ]`,并将 `i, j` 都向右移动一位。\n", + "- 最后 `i + 1` 就是不重复数组的长度。" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "class Solution:\n", + " def removeDuplicates(self, nums) -> int:\n", + " '''\n", + " 执行用时: 48 ms , 在所有 Python3 提交中击败了 76.34% 的用户\n", + " 内存消耗: 14.8 MB , 在所有 Python3 提交中击败了 8.16% 的用户\n", + "\n", + " '''\n", + " i = 0\n", + " for j in range(1, len(nums)):\n", + " if nums[i] != nums[j]:\n", + " i += 1\n", + " nums[i] = nums[j]\n", + " return i + 1\n", + " \n", + " \n", + "s = Solution()\n", + "arr = [1,1,2]\n", + "assert s.removeDuplicates(arr) == 2\n", + "assert arr[:2] == [1, 2]\n", + "arr = [0,0,1,1,1,2,2,3,3,4]\n", + "assert s.removeDuplicates(arr) == 5\n", + "assert arr[:5] == [0, 1, 2, 3, 4]" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/0035-\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.ipynb" "b/notebook/LeetCode/0035-\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.ipynb" new file mode 100644 index 0000000..d2dd339 --- /dev/null +++ "b/notebook/LeetCode/0035-\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.ipynb" @@ -0,0 +1,99 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:简单\n", + "\n", + "知识点:数组、二分查找\n", + "\n", + "地址:https://leetcode-cn.com/problems/search-insert-position/\n", + "\n", + "给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。\n", + "\n", + "你可以假设数组中无重复元素。\n", + "\n", + "示例 1:\n", + "\n", + " 输入: [1,3,5,6], 5\n", + " 输出: 2\n", + "示例 2:\n", + "\n", + " 输入: [1,3,5,6], 2\n", + " 输出: 1\n", + "示例 3:\n", + "\n", + " 输入: [1,3,5,6], 7\n", + " 输出: 4\n", + "示例 4:\n", + "\n", + " 输入: [1,3,5,6], 0\n", + " 输出: 0\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "done\n" + ] + } + ], + "source": [ + "class Solution:\n", + " def searchInsert(self, nums, target) -> int:\n", + " left = 0\n", + " right = len(nums)- 1\n", + "\n", + " while left <= right:\n", + " mid = left + (right - left) // 2\n", + " val = nums[mid]\n", + " if val == target:\n", + " return mid\n", + " elif target > val:\n", + " left = mid + 1\n", + " else:\n", + " right = mid - 1\n", + " return left\n", + " \n", + " \n", + "\n", + "s = Solution()\n", + "assert s.searchInsert([1,3,5,6], 5) == 2\n", + "assert s.searchInsert([1,3,5,6], 2) == 1\n", + "assert s.searchInsert([1,3,5,6], 7) == 4\n", + "assert s.searchInsert([1,3,5,6], 0) == 0\n", + "assert s.searchInsert([1], 0) == 0\n", + "assert s.searchInsert([1], 1) == 0\n", + "print('done')" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git "a/notebook/LeetCode/\351\235\242\350\257\225\351\242\230-02.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.ipynb" "b/notebook/LeetCode/\351\235\242\350\257\225\351\242\230-02.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.ipynb" new file mode 100644 index 0000000..1a3e6e1 --- /dev/null +++ "b/notebook/LeetCode/\351\235\242\350\257\225\351\242\230-02.01-\347\247\273\351\231\244\351\207\215\345\244\215\350\212\202\347\202\271.ipynb" @@ -0,0 +1,145 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "难度:简单\n", + "\n", + "知识点:链表\n", + "\n", + "地址:https://leetcode-cn.com/problems/remove-duplicate-node-lcci/\n", + "\n", + "编写代码,移除未排序链表中的重复节点。保留最开始出现的节点。\n", + "\n", + "示例1:\n", + "\n", + " 输入:[1, 2, 3, 3, 2, 1]\n", + " 输出:[1, 2, 3]\n", + "示例2:\n", + "\n", + " 输入:[1, 1, 1, 1, 2]\n", + " 输出:[1, 2]\n", + "提示:\n", + "\n", + " 链表长度在[0, 20000]范围内。\n", + " 链表元素在[0, 20000]范围内。\n", + "进阶:\n", + "\n", + " 如果不得使用临时缓冲区,该怎么解决?\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 思路1\n", + "- 使用哈希表来做重复节点的过滤,使用新链表来装数据\n", + "- 遍历原链表,如果节点不在哈希表中,则加入到新链表中。如果节点已经存在,则跳过\n", + "- 最后返回新链表" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "from utils import ListNode\n", + "from utils import array2listnode\n", + "from utils import listnode2array\n", + "\n", + "class Solution:\n", + " def removeDuplicateNodes(self, head: ListNode) -> ListNode:\n", + " '''\n", + " 执行用时: 96 ms , 在所有 Python3 提交中击败了 44.85% 的用户\n", + " 内存消耗: 23 MB , 在所有 Python3 提交中击败了 100.00% 的用户\n", + " '''\n", + " l3 = ListNode(0)\n", + " l4 = l3\n", + " stack = set()\n", + " while head:\n", + " val = head.val\n", + " if val not in stack:\n", + " stack.add(val)\n", + " l4.next = ListNode(val)\n", + " l4 = l4.next\n", + " head = head.next\n", + " return l3.next\n", + "\n", + "s = Solution()\n", + "assert listnode2array(s.removeDuplicateNodes(array2listnode([1, 2, 3, 3, 2, 1]))) == [1, 2, 3]\n", + "assert listnode2array(s.removeDuplicateNodes(array2listnode([1, 1, 1, 1, 2]))) == [1, 2]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 思路2\n", + "- 整体思路与上面相同,只是不用新链表,而是在原链表中做删除\n", + "- 如果 `head.next` 是否出现在哈希表中,如果出现过,则 `head.next = head.next.next` 跳过\n", + "- 最后返回当前链表即可" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "from utils import ListNode\n", + "from utils import array2listnode\n", + "from utils import listnode2array\n", + "\n", + "class Solution:\n", + " def removeDuplicateNodes(self, head: ListNode) -> ListNode:\n", + " '''\n", + " 执行用时: 84 ms , 在所有 Python3 提交中击败了 78.10% 的用户\n", + " 内存消耗: 19.9 MB , 在所有 Python3 提交中击败了 100.00%\n", + "\n", + " '''\n", + " if not head:\n", + " return head\n", + " l4 = head\n", + " stack = {head.val}\n", + " while l4.next:\n", + " n = l4.next\n", + " if n.val not in stack:\n", + " stack.add(n.val)\n", + " l4 = l4.next\n", + " else:\n", + " l4.next = l4.next.next\n", + " \n", + " return head\n", + "\n", + "s = Solution()\n", + "assert listnode2array(s.removeDuplicateNodes(array2listnode([1, 2, 3, 3, 2, 1]))) == [1, 2, 3]\n", + "assert listnode2array(s.removeDuplicateNodes(array2listnode([1, 1, 1, 1, 2]))) == [1, 2]" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/notebook/commands/find.ipynb b/notebook/commands/find.ipynb new file mode 100644 index 0000000..028964b --- /dev/null +++ b/notebook/commands/find.ipynb @@ -0,0 +1,902 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + ".\r\n", + "./find.ipynb\r\n", + "./.ipynb_checkpoints\r\n", + "./.ipynb_checkpoints/find-checkpoint.ipynb\r\n" + ] + } + ], + "source": [ + "# 查找当前目录及子目录下所有文件\n", + "!find ." + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "./find.ipynb\r\n", + "./.ipynb_checkpoints/find-checkpoint.ipynb\r\n" + ] + } + ], + "source": [ + "# 查找当前目录及子目录下所有 .ipynb 后缀的文件\n", + "!find . -name \"*.ipynb\"" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "./find.ipynb\r\n", + "./.ipynb_checkpoints/find-checkpoint.ipynb\r\n" + ] + } + ], + "source": [ + "# 忽略大小写\n", + "!find . -iname \"*.ipynb\"" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + ".\r\n", + "./.ipynb_checkpoints\r\n" + ] + } + ], + "source": [ + "# 查找当前目录及子目录下所有不是 .ipynb 后缀的文件\n", + "!find . ! -name \"*.ipynb\"" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + ".\r\n", + "./Untitled.ipynb\r\n", + "./.ipynb_checkpoints\r\n" + ] + } + ], + "source": [ + "# 向下查找 1 层深度\n", + "!find . -maxdepth 1 " + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "./find.ipynb\r\n", + "./.ipynb_checkpoints/find-checkpoint.ipynb\r\n" + ] + } + ], + "source": [ + "# 根据文件类型进行搜索\n", + "!find . -type f" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "类型参数列表:\n", + "\n", + "- f 普通文件\n", + "- l 符号连接\n", + "- d 目录\n", + "- c 字符设备\n", + "- b 块设备\n", + "- s 套接字\n", + "- p Fifo" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "../config.py\r\n", + "../create_index.py\r\n" + ] + } + ], + "source": [ + "# 查找上层目录并多匹配\n", + "!find .. -name \"*.py\" -o -name \"*.pdf\"" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "./find.ipynb\r\n", + "./.ipynb_checkpoints\r\n", + "./.ipynb_checkpoints/find-checkpoint.ipynb\r\n" + ] + } + ], + "source": [ + "# 匹配文件路径或者文件\n", + "!find . -path \"*ipynb*\"" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "./find.ipynb\r\n", + "./.ipynb_checkpoints/find-checkpoint.ipynb\r\n" + ] + } + ], + "source": [ + "# 基于正则表达式匹配文件路径\n", + "!find . -regex \".*ipynb\"" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "./find.ipynb\r\n", + "./.ipynb_checkpoints/find-checkpoint.ipynb\r\n" + ] + } + ], + "source": [ + "# 搜索大于 1k 的文件\n", + "!find . -type f -size +1k" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "./find.ipynb\r\n", + "./.ipynb_checkpoints/find-checkpoint.ipynb\r\n" + ] + } + ], + "source": [ + "# 搜索小于 100k 的文件\n", + "!find . -type f -size -100k" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [], + "source": [ + "# 搜索等于 100k 的文件\n", + "!find . -type f -size 100k" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "文件大小单元:\n", + "\n", + "- b —— 块(512字节)\n", + "- c —— 字节\n", + "- w —— 字(2字节)\n", + "- k —— 千字节\n", + "- M —— 兆字节\n", + "- G —— 吉字节" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\r\n", + "FIND(1) BSD General Commands Manual FIND(1)\r\n", + "\r\n", + "N\bNA\bAM\bME\bE\r\n", + " f\bfi\bin\bnd\bd -- walk a file hierarchy\r\n", + "\r\n", + "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS\r\n", + " f\bfi\bin\bnd\bd [-\b-H\bH | -\b-L\bL | -\b-P\bP] [-\b-E\bEX\bXd\bds\bsx\bx] [-\b-f\bf _\bp_\ba_\bt_\bh] _\bp_\ba_\bt_\bh _\b._\b._\b. [_\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn]\r\n", + " f\bfi\bin\bnd\bd [-\b-H\bH | -\b-L\bL | -\b-P\bP] [-\b-E\bEX\bXd\bds\bsx\bx] -\b-f\bf _\bp_\ba_\bt_\bh [_\bp_\ba_\bt_\bh _\b._\b._\b.] [_\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn]\r\n", + "\r\n", + "D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN\r\n", + " The f\bfi\bin\bnd\bd utility recursively descends the directory tree for each _\bp_\ba_\bt_\bh\r\n", + " listed, evaluating an _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn (composed of the ``primaries'' and\r\n", + " ``operands'' listed below) in terms of each file in the tree.\r\n", + "\r\n", + " The options are as follows:\r\n", + "\r\n", + " -\b-E\bE Interpret regular expressions followed by -\b-r\bre\beg\bge\bex\bx and -\b-i\bir\bre\beg\bge\bex\bx pri-\r\n", + " maries as extended (modern) regular expressions rather than basic\r\n", + " regular expressions (BRE's). The re_format(7) manual page fully\r\n", + " describes both formats.\r\n", + "\r\n", + " -\b-H\bH Cause the file information and file type (see stat(2)) returned\r\n", + " for each symbolic link specified on the command line to be those\r\n", + " of the file referenced by the link, not the link itself. If the\r\n", + " referenced file does not exist, the file information and type\r\n", + " will be for the link itself. File information of all symbolic\r\n", + " links not on the command line is that of the link itself.\r\n", + "\r\n", + " -\b-L\bL Cause the file information and file type (see stat(2)) returned\r\n", + " for each symbolic link to be those of the file referenced by the\r\n", + " link, not the link itself. If the referenced file does not\r\n", + " exist, the file information and type will be for the link itself.\r\n", + "\r\n", + " This option is equivalent to the deprecated -\b-f\bfo\bol\bll\blo\bow\bw primary.\r\n", + "\r\n", + " -\b-P\bP Cause the file information and file type (see stat(2)) returned\r\n", + " for each symbolic link to be those of the link itself. This is\r\n", + " the default.\r\n", + "\r\n", + " -\b-X\bX Permit f\bfi\bin\bnd\bd to be safely used in conjunction with xargs(1). If a\r\n", + " file name contains any of the delimiting characters used by\r\n", + " xargs(1), a diagnostic message is displayed on standard error,\r\n", + " and the file is skipped. The delimiting characters include sin-\r\n", + " gle (`` ' '') and double (`` \" '') quotes, backslash (``\\''),\r\n", + " space, tab and newline characters.\r\n", + "\r\n", + " However, you may wish to consider the -\b-p\bpr\bri\bin\bnt\bt0\b0 primary in conjunc-\r\n", + " tion with ``x\bxa\bar\brg\bgs\bs -\b-0\b0'' as an effective alternative.\r\n", + "\r\n", + " -\b-d\bd Cause f\bfi\bin\bnd\bd to perform a depth-first traversal, i.e., directories\r\n", + " are visited in post-order and all entries in a directory will be\r\n", + " acted on before the directory itself. By default, f\bfi\bin\bnd\bd visits\r\n", + " directories in pre-order, i.e., before their contents. Note, the\r\n", + " default is _\bn_\bo_\bt a breadth-first traversal.\r\n", + "\r\n", + " This option is equivalent to the -\b-d\bde\bep\bpt\bth\bh primary of IEEE Std\r\n", + " 1003.1-2001 (``POSIX.1''). The -\b-d\bd option can be useful when f\bfi\bin\bnd\bd\r\n", + " is used with cpio(1) to process files that are contained in\r\n", + " directories with unusual permissions. It ensures that you have\r\n", + " write permission while you are placing files in a directory, then\r\n", + " sets the directory's permissions as the last thing.\r\n", + "\r\n", + " -\b-f\bf Specify a file hierarchy for f\bfi\bin\bnd\bd to traverse. File hierarchies\r\n", + " may also be specified as the operands immediately following the\r\n", + " options.\r\n", + "\r\n", + " -\b-s\bs Cause f\bfi\bin\bnd\bd to traverse the file hierarchies in lexicographical\r\n", + " order, i.e., alphabetical order within each directory. Note:\r\n", + " `find -s' and `find | sort' may give different results.\r\n", + "\r\n", + " -\b-x\bx Prevent f\bfi\bin\bnd\bd from descending into directories that have a device\r\n", + " number different than that of the file from which the descent\r\n", + " began.\r\n", + "\r\n", + " This option is equivalent to the deprecated -\b-x\bxd\bde\bev\bv primary.\r\n", + "\r\n", + "P\bPR\bRI\bIM\bMA\bAR\bRI\bIE\bES\bS\r\n", + " All primaries which take a numeric argument allow the number to be pre-\r\n", + " ceded by a plus sign (``+'') or a minus sign (``-''). A preceding plus\r\n", + " sign means ``more than n'', a preceding minus sign means ``less than n''\r\n", + " and neither means ``exactly n''.\r\n", + "\r\n", + " -\b-B\bBm\bmi\bin\bn _\bn\r\n", + " True if the difference between the time of a file's inode cre-\r\n", + " ation and the time f\bfi\bin\bnd\bd was started, rounded up to the next full\r\n", + " minute, is _\bn minutes.\r\n", + "\r\n", + " -\b-B\bBn\bne\bew\bwe\ber\br _\bf_\bi_\bl_\be\r\n", + " Same as -\b-n\bne\bew\bwe\ber\brB\bBm\bm.\r\n", + "\r\n", + " -\b-B\bBt\bti\bim\bme\be _\bn[s\bsm\bmh\bhd\bdw\bw]\r\n", + " If no units are specified, this primary evaluates to true if the\r\n", + " difference between the time of a file's inode creation and the\r\n", + " time f\bfi\bin\bnd\bd was started, rounded up to the next full 24-hour\r\n", + " period, is _\bn 24-hour periods.\r\n", + "\r\n", + " If units are specified, this primary evaluates to true if the\r\n", + " difference between the time of a file's inode creation and the\r\n", + " time f\bfi\bin\bnd\bd was started is exactly _\bn units. Please refer to the\r\n", + " -\b-a\bat\bti\bim\bme\be primary description for information on supported time\r\n", + " units.\r\n", + "\r\n", + " -\b-a\bac\bcl\bl May be used in conjunction with other primaries to locate files\r\n", + " with extended ACLs. See acl(3) for more information.\r\n", + "\r\n", + " -\b-a\bam\bmi\bin\bn _\bn\r\n", + " True if the difference between the file last access time and the\r\n", + " time f\bfi\bin\bnd\bd was started, rounded up to the next full minute, is _\bn\r\n", + " minutes.\r\n", + "\r\n", + " -\b-a\ban\bne\bew\bwe\ber\br _\bf_\bi_\bl_\be\r\n", + " Same as -\b-n\bne\bew\bwe\ber\bra\bam\bm.\r\n", + "\r\n", + " -\b-a\bat\bti\bim\bme\be _\bn[s\bsm\bmh\bhd\bdw\bw]\r\n", + " If no units are specified, this primary evaluates to true if the\r\n", + " difference between the file last access time and the time f\bfi\bin\bnd\bd\r\n", + " was started, rounded up to the next full 24-hour period, is _\bn\r\n", + " 24-hour periods.\r\n", + "\r\n", + " If units are specified, this primary evaluates to true if the\r\n", + " difference between the file last access time and the time f\bfi\bin\bnd\bd\r\n", + " was started is exactly _\bn units. Possible time units are as fol-\r\n", + " lows:\r\n", + "\r\n", + " s\bs second\r\n", + " m\bm minute (60 seconds)\r\n", + " h\bh hour (60 minutes)\r\n", + " d\bd day (24 hours)\r\n", + " w\bw week (7 days)\r\n", + "\r\n", + " Any number of units may be combined in one -\b-a\bat\bti\bim\bme\be argument, for\r\n", + " example, ``-atime -1h30m''. Units are probably only useful when\r\n", + " used in conjunction with the +\b+ or -\b- modifier.\r\n", + "\r\n", + " -\b-c\bcm\bmi\bin\bn _\bn\r\n", + " True if the difference between the time of last change of file\r\n", + " status information and the time f\bfi\bin\bnd\bd was started, rounded up to\r\n", + " the next full minute, is _\bn minutes.\r\n", + "\r\n", + " -\b-c\bcn\bne\bew\bwe\ber\br _\bf_\bi_\bl_\be\r\n", + " Same as -\b-n\bne\bew\bwe\ber\brc\bcm\bm.\r\n", + "\r\n", + " -\b-c\bct\bti\bim\bme\be _\bn[s\bsm\bmh\bhd\bdw\bw]\r\n", + " If no units are specified, this primary evaluates to true if the\r\n", + " difference between the time of last change of file status infor-\r\n", + " mation and the time f\bfi\bin\bnd\bd was started, rounded up to the next full\r\n", + " 24-hour period, is _\bn 24-hour periods.\r\n", + "\r\n", + " If units are specified, this primary evaluates to true if the\r\n", + " difference between the time of last change of file status infor-\r\n", + " mation and the time f\bfi\bin\bnd\bd was started is exactly _\bn units. Please\r\n", + " refer to the -\b-a\bat\bti\bim\bme\be primary description for information on sup-\r\n", + " ported time units.\r\n", + "\r\n", + " -\b-d\bd Same as d\bde\bep\bpt\bth\bh. GNU find implements this as a primary in mistaken\r\n", + " emulation of FreeBSD find(1).\r\n", + "\r\n", + " -\b-d\bde\bel\ble\bet\bte\be\r\n", + " Delete found files and/or directories. Always returns true.\r\n", + " This executes from the current working directory as f\bfi\bin\bnd\bd recurses\r\n", + " down the tree. It will not attempt to delete a filename with a\r\n", + " ``_\b/'' character in its pathname relative to ``_\b.'' for security\r\n", + " reasons. Depth-first traversal processing is implied by this\r\n", + " option. Following symlinks is incompatible with this option.\r\n", + "\r\n", + " -\b-d\bde\bep\bpt\bth\bh Always true; same as the -\b-d\bd option.\r\n", + "\r\n", + " -\b-d\bde\bep\bpt\bth\bh _\bn\r\n", + " True if the depth of the file relative to the starting point of\r\n", + " the traversal is _\bn.\r\n", + "\r\n", + " -\b-e\bem\bmp\bpt\bty\by True if the current file or directory is empty.\r\n", + "\r\n", + " -\b-e\bex\bxe\bec\bc _\bu_\bt_\bi_\bl_\bi_\bt_\by [_\ba_\br_\bg_\bu_\bm_\be_\bn_\bt _\b._\b._\b.] ;\r\n", + " True if the program named _\bu_\bt_\bi_\bl_\bi_\bt_\by returns a zero value as its\r\n", + " exit status. Optional _\ba_\br_\bg_\bu_\bm_\be_\bn_\bt_\bs may be passed to the utility.\r\n", + " The expression must be terminated by a semicolon (``;''). If you\r\n", + " invoke f\bfi\bin\bnd\bd from a shell you may need to quote the semicolon if\r\n", + " the shell would otherwise treat it as a control operator. If the\r\n", + " string ``{}'' appears anywhere in the utility name or the argu-\r\n", + " ments it is replaced by the pathname of the current file.\r\n", + " _\bU_\bt_\bi_\bl_\bi_\bt_\by will be executed from the directory from which f\bfi\bin\bnd\bd was\r\n", + " executed. _\bU_\bt_\bi_\bl_\bi_\bt_\by and _\ba_\br_\bg_\bu_\bm_\be_\bn_\bt_\bs are not subject to the further\r\n", + " expansion of shell patterns and constructs.\r\n", + "\r\n", + " -\b-e\bex\bxe\bec\bc _\bu_\bt_\bi_\bl_\bi_\bt_\by [_\ba_\br_\bg_\bu_\bm_\be_\bn_\bt _\b._\b._\b.] {} +\r\n", + " Same as -\b-e\bex\bxe\bec\bc, except that ``{}'' is replaced with as many path-\r\n", + " names as possible for each invocation of _\bu_\bt_\bi_\bl_\bi_\bt_\by. This behaviour\r\n", + " is similar to that of xargs(1).\r\n", + "\r\n", + " -\b-e\bex\bxe\bec\bcd\bdi\bir\br _\bu_\bt_\bi_\bl_\bi_\bt_\by [_\ba_\br_\bg_\bu_\bm_\be_\bn_\bt _\b._\b._\b.] ;\r\n", + " The -\b-e\bex\bxe\bec\bcd\bdi\bir\br primary is identical to the -\b-e\bex\bxe\bec\bc primary with the\r\n", + " exception that _\bu_\bt_\bi_\bl_\bi_\bt_\by will be executed from the directory that\r\n", + " holds the current file. The filename substituted for the string\r\n", + " ``{}'' is not qualified.\r\n", + "\r\n", + " -\b-e\bex\bxe\bec\bcd\bdi\bir\br _\bu_\bt_\bi_\bl_\bi_\bt_\by [_\ba_\br_\bg_\bu_\bm_\be_\bn_\bt _\b._\b._\b.] {} +\r\n", + " Same as -\b-e\bex\bxe\bec\bcd\bdi\bir\br, except that ``{}'' is replaced with as many\r\n", + " pathnames as possible for each invocation of _\bu_\bt_\bi_\bl_\bi_\bt_\by. This be-\r\n", + " haviour is similar to that of xargs(1).\r\n", + "\r\n", + " -\b-f\bfl\bla\bag\bgs\bs [-\b-|+\b+]_\bf_\bl_\ba_\bg_\bs,_\bn_\bo_\bt_\bf_\bl_\ba_\bg_\bs\r\n", + " The flags are specified using symbolic names (see chflags(1)).\r\n", + " Those with the \"no\" prefix (except \"nodump\") are said to be\r\n", + " _\bn_\bo_\bt_\bf_\bl_\ba_\bg_\bs. Flags in _\bf_\bl_\ba_\bg_\bs are checked to be set, and flags in\r\n", + " _\bn_\bo_\bt_\bf_\bl_\ba_\bg_\bs are checked to be not set. Note that this is different\r\n", + " from -\b-p\bpe\ber\brm\bm, which only allows the user to specify mode bits that\r\n", + " are set.\r\n", + "\r\n", + " If flags are preceded by a dash (``-''), this primary evaluates\r\n", + " to true if at least all of the bits in _\bf_\bl_\ba_\bg_\bs and none of the bits\r\n", + " in _\bn_\bo_\bt_\bf_\bl_\ba_\bg_\bs are set in the file's flags bits. If flags are pre-\r\n", + " ceded by a plus (``+''), this primary evaluates to true if any of\r\n", + " the bits in _\bf_\bl_\ba_\bg_\bs is set in the file's flags bits, or any of the\r\n", + " bits in _\bn_\bo_\bt_\bf_\bl_\ba_\bg_\bs is not set in the file's flags bits. Otherwise,\r\n", + " this primary evaluates to true if the bits in _\bf_\bl_\ba_\bg_\bs exactly match\r\n", + " the file's flags bits, and none of the _\bf_\bl_\ba_\bg_\bs bits match those of\r\n", + " _\bn_\bo_\bt_\bf_\bl_\ba_\bg_\bs.\r\n", + "\r\n", + " -\b-f\bfs\bst\bty\byp\bpe\be _\bt_\by_\bp_\be\r\n", + " True if the file is contained in a file system of type _\bt_\by_\bp_\be. The\r\n", + " lsvfs(1) command can be used to find out the types of file sys-\r\n", + " tems that are available on the system. In addition, there are\r\n", + " two pseudo-types, ``local'' and ``rdonly''. The former matches\r\n", + " any file system physically mounted on the system where the f\bfi\bin\bnd\bd\r\n", + " is being executed and the latter matches any file system which is\r\n", + " mounted read-only.\r\n", + "\r\n", + " -\b-g\bgi\bid\bd _\bg_\bn_\ba_\bm_\be\r\n", + " The same thing as _\b-_\bg_\br_\bo_\bu_\bp _\bg_\bn_\ba_\bm_\be for compatibility with GNU find.\r\n", + " GNU find imposes a restriction that _\bg_\bn_\ba_\bm_\be is numeric, while\r\n", + " find(1) does not.\r\n", + "\r\n", + " -\b-g\bgr\bro\bou\bup\bp _\bg_\bn_\ba_\bm_\be\r\n", + " True if the file belongs to the group _\bg_\bn_\ba_\bm_\be. If _\bg_\bn_\ba_\bm_\be is numeric\r\n", + " and there is no such group name, then _\bg_\bn_\ba_\bm_\be is treated as a group\r\n", + " ID.\r\n", + "\r\n", + " -\b-i\big\bgn\bno\bor\bre\be_\b_r\bre\bea\bad\bdd\bdi\bir\br_\b_r\bra\bac\bce\be\r\n", + " This option is for GNU find compatibility and is ignored.\r\n", + "\r\n", + " -\b-i\bil\bln\bna\bam\bme\be _\bp_\ba_\bt_\bt_\be_\br_\bn\r\n", + " Like -\b-l\bln\bna\bam\bme\be, but the match is case insensitive. This is a GNU\r\n", + " find extension.\r\n", + "\r\n", + " -\b-i\bin\bna\bam\bme\be _\bp_\ba_\bt_\bt_\be_\br_\bn\r\n", + " Like -\b-n\bna\bam\bme\be, but the match is case insensitive.\r\n", + "\r\n", + " -\b-i\bin\bnu\bum\bm _\bn\r\n", + " True if the file has inode number _\bn.\r\n", + "\r\n", + " -\b-i\bip\bpa\bat\bth\bh _\bp_\ba_\bt_\bt_\be_\br_\bn\r\n", + " Like -\b-p\bpa\bat\bth\bh, but the match is case insensitive.\r\n", + "\r\n", + " -\b-i\bir\bre\beg\bge\bex\bx _\bp_\ba_\bt_\bt_\be_\br_\bn\r\n", + " Like -\b-r\bre\beg\bge\bex\bx, but the match is case insensitive.\r\n", + "\r\n", + " -\b-i\biw\bwh\bho\bol\ble\ben\bna\bam\bme\be _\bp_\ba_\bt_\bt_\be_\br_\bn\r\n", + " The same thing as -\b-i\bip\bpa\bat\bth\bh, for GNU find compatibility.\r\n", + "\r\n", + " -\b-l\bli\bin\bnk\bks\bs _\bn\r\n", + " True if the file has _\bn links.\r\n", + "\r\n", + " -\b-l\bln\bna\bam\bme\be _\bp_\ba_\bt_\bt_\be_\br_\bn\r\n", + " Like -\b-n\bna\bam\bme\be, but the contents of the symbolic link are matched\r\n", + " instead of the file name. Note that this only matches broken\r\n", + " symbolic links if symbolic links are being followed. This is a\r\n", + " GNU find extension.\r\n", + "\r\n", + " -\b-l\bls\bs This primary always evaluates to true. The following information\r\n", + " for the current file is written to standard output: its inode\r\n", + " number, size in 512-byte blocks, file permissions, number of hard\r\n", + " links, owner, group, size in bytes, last modification time, and\r\n", + " pathname. If the file is a block or character special file, the\r\n", + " device number will be displayed instead of the size in bytes. If\r\n", + " the file is a symbolic link, the pathname of the linked-to file\r\n", + " will be displayed preceded by ``->''. The format is identical to\r\n", + " that produced by ``l\bls\bs -\b-d\bdg\bgi\bil\bls\bs''.\r\n", + "\r\n", + " -\b-m\bma\bax\bxd\bde\bep\bpt\bth\bh _\bn\r\n", + " Always true; descend at most _\bn directory levels below the command\r\n", + " line arguments. If any -\b-m\bma\bax\bxd\bde\bep\bpt\bth\bh primary is specified, it\r\n", + " applies to the entire expression even if it would not normally be\r\n", + " evaluated. ``-\b-m\bma\bax\bxd\bde\bep\bpt\bth\bh 0'' limits the whole search to the com-\r\n", + " mand line arguments.\r\n", + "\r\n", + " -\b-m\bmi\bin\bnd\bde\bep\bpt\bth\bh _\bn\r\n", + " Always true; do not apply any tests or actions at levels less\r\n", + " than _\bn. If any -\b-m\bmi\bin\bnd\bde\bep\bpt\bth\bh primary is specified, it applies to the\r\n", + " entire expression even if it would not normally be evaluated.\r\n", + " ``-\b-m\bmi\bin\bnd\bde\bep\bpt\bth\bh 1'' processes all but the command line arguments.\r\n", + "\r\n", + " -\b-m\bmm\bmi\bin\bn _\bn\r\n", + " True if the difference between the file last modification time\r\n", + " and the time f\bfi\bin\bnd\bd was started, rounded up to the next full\r\n", + " minute, is _\bn minutes.\r\n", + "\r\n", + " -\b-m\bmn\bne\bew\bwe\ber\br _\bf_\bi_\bl_\be\r\n", + " Same as -\b-n\bne\bew\bwe\ber\br.\r\n", + "\r\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + " -\b-m\bmo\bou\bun\bnt\bt The same thing as -\b-x\bxd\bde\bev\bv, for GNU find compatibility.\r\n", + "\r\n", + " -\b-m\bmt\bti\bim\bme\be _\bn[s\bsm\bmh\bhd\bdw\bw]\r\n", + " If no units are specified, this primary evaluates to true if the\r\n", + " difference between the file last modification time and the time\r\n", + " f\bfi\bin\bnd\bd was started, rounded up to the next full 24-hour period, is\r\n", + " _\bn 24-hour periods.\r\n", + "\r\n", + " If units are specified, this primary evaluates to true if the\r\n", + " difference between the file last modification time and the time\r\n", + " f\bfi\bin\bnd\bd was started is exactly _\bn units. Please refer to the -\b-a\bat\bti\bim\bme\be\r\n", + " primary description for information on supported time units.\r\n", + "\r\n", + " -\b-n\bna\bam\bme\be _\bp_\ba_\bt_\bt_\be_\br_\bn\r\n", + " True if the last component of the pathname being examined matches\r\n", + " _\bp_\ba_\bt_\bt_\be_\br_\bn. Special shell pattern matching characters (``['',\r\n", + " ``]'', ``*'', and ``?'') may be used as part of _\bp_\ba_\bt_\bt_\be_\br_\bn. These\r\n", + " characters may be matched explicitly by escaping them with a\r\n", + " backslash (``\\'').\r\n", + "\r\n", + " -\b-n\bne\bew\bwe\ber\br _\bf_\bi_\bl_\be\r\n", + " True if the current file has a more recent last modification time\r\n", + " than _\bf_\bi_\bl_\be.\r\n", + "\r\n", + " -\b-n\bne\bew\bwe\ber\br_\bX_\bY _\bf_\bi_\bl_\be\r\n", + " True if the current file has a more recent last access time\r\n", + " (_\bX=a\ba), inode creation time (_\bX=B\bB), change time (_\bX=c\bc), or modifica-\r\n", + " tion time (_\bX=m\bm) than the last access time (_\bY=a\ba), inode creation\r\n", + " time (_\bY=B\bB), change time (_\bY=c\bc), or modification time (_\bY=m\bm) of\r\n", + " _\bf_\bi_\bl_\be. In addition, if _\bY=t\bt, then _\bf_\bi_\bl_\be is instead interpreted as a\r\n", + " direct date specification of the form understood by cvs(1). Note\r\n", + " that -\b-n\bne\bew\bwe\ber\brm\bmm\bm is equivalent to -\b-n\bne\bew\bwe\ber\br.\r\n", + "\r\n", + " -\b-n\bno\bog\bgr\bro\bou\bup\bp\r\n", + " True if the file belongs to an unknown group.\r\n", + "\r\n", + " -\b-n\bno\boi\big\bgn\bno\bor\bre\be_\b_r\bre\bea\bad\bdd\bdi\bir\br_\b_r\bra\bac\bce\be\r\n", + " This option is for GNU find compatibility and is ignored.\r\n", + "\r\n", + " -\b-n\bno\bol\ble\bea\baf\bf\r\n", + " This option is for GNU find compatibility. In GNU find it dis-\r\n", + " ables an optimization not relevant to find(1), so it is ignored.\r\n", + "\r\n", + " -\b-n\bno\bou\bus\bse\ber\br\r\n", + " True if the file belongs to an unknown user.\r\n", + "\r\n", + " -\b-o\bok\bk _\bu_\bt_\bi_\bl_\bi_\bt_\by [_\ba_\br_\bg_\bu_\bm_\be_\bn_\bt _\b._\b._\b.] ;\r\n", + " The -\b-o\bok\bk primary is identical to the -\b-e\bex\bxe\bec\bc primary with the excep-\r\n", + " tion that f\bfi\bin\bnd\bd requests user affirmation for the execution of the\r\n", + " _\bu_\bt_\bi_\bl_\bi_\bt_\by by printing a message to the terminal and reading a\r\n", + " response. If the response is not affirmative (`y' in the\r\n", + " ``POSIX'' locale), the command is not executed and the value of\r\n", + " the -\b-o\bok\bk expression is false.\r\n", + "\r\n", + " -\b-o\bok\bkd\bdi\bir\br _\bu_\bt_\bi_\bl_\bi_\bt_\by [_\ba_\br_\bg_\bu_\bm_\be_\bn_\bt _\b._\b._\b.] ;\r\n", + " The -\b-o\bok\bkd\bdi\bir\br primary is identical to the -\b-e\bex\bxe\bec\bcd\bdi\bir\br primary with the\r\n", + " same exception as described for the -\b-o\bok\bk primary.\r\n", + "\r\n", + " -\b-p\bpa\bat\bth\bh _\bp_\ba_\bt_\bt_\be_\br_\bn\r\n", + " True if the pathname being examined matches _\bp_\ba_\bt_\bt_\be_\br_\bn. Special\r\n", + " shell pattern matching characters (``['', ``]'', ``*'', and\r\n", + " ``?'') may be used as part of _\bp_\ba_\bt_\bt_\be_\br_\bn. These characters may be\r\n", + " matched explicitly by escaping them with a backslash (``\\'').\r\n", + " Slashes (``/'') are treated as normal characters and do not have\r\n", + " to be matched explicitly.\r\n", + "\r\n", + " -\b-p\bpe\ber\brm\bm [-\b-|+\b+]_\bm_\bo_\bd_\be\r\n", + " The _\bm_\bo_\bd_\be may be either symbolic (see chmod(1)) or an octal num-\r\n", + " ber. If the _\bm_\bo_\bd_\be is symbolic, a starting value of zero is\r\n", + " assumed and the _\bm_\bo_\bd_\be sets or clears permissions without regard to\r\n", + " the process' file mode creation mask. If the _\bm_\bo_\bd_\be is octal, only\r\n", + " bits 07777 (S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG |\r\n", + " S_IRWXO) of the file's mode bits participate in the comparison.\r\n", + " If the _\bm_\bo_\bd_\be is preceded by a dash (``-''), this primary evaluates\r\n", + " to true if at least all of the bits in the _\bm_\bo_\bd_\be are set in the\r\n", + " file's mode bits. If the _\bm_\bo_\bd_\be is preceded by a plus (``+''),\r\n", + " this primary evaluates to true if any of the bits in the _\bm_\bo_\bd_\be are\r\n", + " set in the file's mode bits. Otherwise, this primary evaluates\r\n", + " to true if the bits in the _\bm_\bo_\bd_\be exactly match the file's mode\r\n", + " bits. Note, the first character of a symbolic mode may not be a\r\n", + " dash (``-'').\r\n", + "\r\n", + " -\b-p\bpr\bri\bin\bnt\bt This primary always evaluates to true. It prints the pathname of\r\n", + " the current file to standard output. If none of -\b-e\bex\bxe\bec\bc, -\b-l\bls\bs,\r\n", + " -\b-p\bpr\bri\bin\bnt\bt, -\b-p\bpr\bri\bin\bnt\bt0\b0, or -\b-o\bok\bk is specified, the given expression shall\r\n", + " be effectively replaced by (\b( _\bg_\bi_\bv_\be_\bn _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn )\b) -\b-p\bpr\bri\bin\bnt\bt.\r\n", + "\r\n", + " -\b-p\bpr\bri\bin\bnt\bt0\b0\r\n", + " This primary always evaluates to true. It prints the pathname of\r\n", + " the current file to standard output, followed by an ASCII NUL\r\n", + " character (character code 0).\r\n", + "\r\n", + " -\b-p\bpr\bru\bun\bne\be This primary always evaluates to true. It causes f\bfi\bin\bnd\bd to not\r\n", + " descend into the current file. Note, the -\b-p\bpr\bru\bun\bne\be primary has no\r\n", + " effect if the -\b-d\bd option was specified.\r\n", + "\r\n", + " -\b-r\bre\beg\bge\bex\bx _\bp_\ba_\bt_\bt_\be_\br_\bn\r\n", + " True if the whole path of the file matches _\bp_\ba_\bt_\bt_\be_\br_\bn using regular\r\n", + " expression. To match a file named ``_\b._\b/_\bf_\bo_\bo_\b/_\bx_\by_\bz_\bz_\by'', you can use\r\n", + " the regular expression ``.*/[xyz]*'' or ``.*/foo/.*'', but not\r\n", + " ``xyzzy'' or ``/foo/''.\r\n", + "\r\n", + " -\b-s\bsa\bam\bme\bef\bfi\bil\ble\be _\bn_\ba_\bm_\be\r\n", + " True if the file is a hard link to _\bn_\ba_\bm_\be. If the command option\r\n", + " -\b-L\bL is specified, it is also true if the file is a symbolic link\r\n", + " and points to _\bn_\ba_\bm_\be.\r\n", + "\r\n", + " -\b-s\bsi\biz\bze\be _\bn[c\bck\bkM\bMG\bGT\bTP\bP]\r\n", + " True if the file's size, rounded up, in 512-byte blocks is _\bn. If\r\n", + " _\bn is followed by a c\bc, then the primary is true if the file's size\r\n", + " is _\bn bytes (characters). Similarly if _\bn is followed by a scale\r\n", + " indicator then the file's size is compared to _\bn scaled as:\r\n", + "\r\n", + " k\bk kilobytes (1024 bytes)\r\n", + " M\bM megabytes (1024 kilobytes)\r\n", + " G\bG gigabytes (1024 megabytes)\r\n", + " T\bT terabytes (1024 gigabytes)\r\n", + " P\bP petabytes (1024 terabytes)\r\n", + "\r\n", + " -\b-t\bty\byp\bpe\be _\bt\r\n", + " True if the file is of the specified type. Possible file types\r\n", + " are as follows:\r\n", + "\r\n", + " b\bb block special\r\n", + " c\bc character special\r\n", + " d\bd directory\r\n", + " f\bf regular file\r\n", + " l\bl symbolic link\r\n", + " p\bp FIFO\r\n", + " s\bs socket\r\n", + "\r\n", + " -\b-u\bui\bid\bd _\bu_\bn_\ba_\bm_\be\r\n", + " The same thing as _\b-_\bu_\bs_\be_\br _\bu_\bn_\ba_\bm_\be for compatibility with GNU find.\r\n", + " GNU find imposes a restriction that _\bu_\bn_\ba_\bm_\be is numeric, while\r\n", + " find(1) does not.\r\n", + "\r\n", + " -\b-u\bus\bse\ber\br _\bu_\bn_\ba_\bm_\be\r\n", + " True if the file belongs to the user _\bu_\bn_\ba_\bm_\be. If _\bu_\bn_\ba_\bm_\be is numeric\r\n", + " and there is no such user name, then _\bu_\bn_\ba_\bm_\be is treated as a user\r\n", + " ID.\r\n", + "\r\n", + " -\b-w\bwh\bho\bol\ble\ben\bna\bam\bme\be _\bp_\ba_\bt_\bt_\be_\br_\bn\r\n", + " The same thing as -\b-p\bpa\bat\bth\bh, for GNU find compatibility.\r\n", + "\r\n", + " -\b-x\bxa\bat\btt\btr\br True if the file has any extended attributes.\r\n", + "\r\n", + " -\b-x\bxa\bat\btt\btr\brn\bna\bam\bme\be _\bn_\ba_\bm_\be\r\n", + " True if the file has an extended attribute with the specified\r\n", + " _\bn_\ba_\bm_\be.\r\n", + "\r\n", + "O\bOP\bPE\bER\bRA\bAT\bTO\bOR\bRS\bS\r\n", + " The primaries may be combined using the following operators. The opera-\r\n", + " tors are listed in order of decreasing precedence.\r\n", + "\r\n", + " (\b( _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn )\b)\r\n", + " This evaluates to true if the parenthesized expression evaluates\r\n", + " to true.\r\n", + "\r\n", + " !\b! _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn\r\n", + " -\b-n\bno\bot\bt _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn\r\n", + " This is the unary NOT operator. It evaluates to true if the\r\n", + " expression is false.\r\n", + "\r\n", + " -\b-f\bfa\bal\bls\bse\be Always false.\r\n", + " -\b-t\btr\bru\bue\be Always true.\r\n", + "\r\n", + " _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn -\b-a\ban\bnd\bd _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn\r\n", + " _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn\r\n", + " The -\b-a\ban\bnd\bd operator is the logical AND operator. As it is implied\r\n", + " by the juxtaposition of two expressions it does not have to be\r\n", + " specified. The expression evaluates to true if both expressions\r\n", + " are true. The second expression is not evaluated if the first\r\n", + " expression is false.\r\n", + "\r\n", + " _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn -\b-o\bor\br _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn\r\n", + " The -\b-o\bor\br operator is the logical OR operator. The expression\r\n", + " evaluates to true if either the first or the second expression is\r\n", + " true. The second expression is not evaluated if the first\r\n", + " expression is true.\r\n", + "\r\n", + " All operands and primaries must be separate arguments to f\bfi\bin\bnd\bd. Primaries\r\n", + " which themselves take arguments expect each argument to be a separate\r\n", + " argument to f\bfi\bin\bnd\bd.\r\n", + "\r\n", + "E\bEN\bNV\bVI\bIR\bRO\bON\bNM\bME\bEN\bNT\bT\r\n", + " The LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES and LC_TIME environ-\r\n", + " ment variables affect the execution of the f\bfi\bin\bnd\bd utility as described in\r\n", + " environ(7).\r\n", + "\r\n", + "E\bEX\bXA\bAM\bMP\bPL\bLE\bES\bS\r\n", + " The following examples are shown as given to the shell:\r\n", + "\r\n", + " find / \\! -name \"*.c\" -print\r\n", + " Print out a list of all the files whose names do not end in _\b._\bc.\r\n", + "\r\n", + " find / -newer ttt -user wnj -print\r\n", + " Print out a list of all the files owned by user ``wnj'' that are\r\n", + " newer than the file _\bt_\bt_\bt.\r\n", + "\r\n", + " find / \\! \\( -newer ttt -user wnj \\) -print\r\n", + " Print out a list of all the files which are not both newer than\r\n", + " _\bt_\bt_\bt and owned by ``wnj''.\r\n", + "\r\n", + " find / \\( -newer ttt -or -user wnj \\) -print\r\n", + " Print out a list of all the files that are either owned by\r\n", + " ``wnj'' or that are newer than _\bt_\bt_\bt.\r\n", + "\r\n", + " find / -newerct '1 minute ago' -print\r\n", + " Print out a list of all the files whose inode change time is more\r\n", + " recent than the current time minus one minute.\r\n", + "\r\n", + " find / -type f -exec echo {} \\;\r\n", + " Use the echo(1) command to print out a list of all the files.\r\n", + "\r\n", + " find -L /usr/ports/packages -type l -exec rm -- {} +\r\n", + " Delete all broken symbolic links in _\b/_\bu_\bs_\br_\b/_\bp_\bo_\br_\bt_\bs_\b/_\bp_\ba_\bc_\bk_\ba_\bg_\be_\bs.\r\n", + "\r\n", + " find /usr/src -name CVS -prune -o -depth +6 -print\r\n", + " Find files and directories that are at least seven levels deep in\r\n", + " the working directory _\b/_\bu_\bs_\br_\b/_\bs_\br_\bc.\r\n", + "\r\n", + " find /usr/src -name CVS -prune -o -mindepth 7 -print\r\n", + " Is not equivalent to the previous example, since -\b-p\bpr\bru\bun\bne\be is not\r\n", + " evaluated below level seven.\r\n", + "\r\n", + "C\bCO\bOM\bMP\bPA\bAT\bTI\bIB\bBI\bIL\bLI\bIT\bTY\bY\r\n", + " The -\b-f\bfo\bol\bll\blo\bow\bw primary is deprecated; the -\b-L\bL option should be used instead.\r\n", + " See the _\bS_\bT_\bA_\bN_\bD_\bA_\bR_\bD_\bS section below for details.\r\n", + "\r\n", + "S\bSE\bEE\bE A\bAL\bLS\bSO\bO\r\n", + " chflags(1), chmod(1), cvs(1), locate(1), lsvfs(1), whereis(1), which(1),\r\n", + " xargs(1), stat(2), acl(3), fts(3), getgrent(3), getpwent(3), strmode(3),\r\n", + " re_format(7), symlink(7)\r", + "\r\n", + "\r\n", + "S\bST\bTA\bAN\bND\bDA\bAR\bRD\bDS\bS\r\n", + " The f\bfi\bin\bnd\bd utility syntax is a superset of the syntax specified by the IEEE\r\n", + " Std 1003.1-2001 (``POSIX.1'') standard.\r\n", + "\r\n", + " All the single character options except -\b-H\bH and -\b-L\bL as well as -\b-a\bam\bmi\bin\bn,\r\n", + " -\b-a\ban\bne\bew\bwe\ber\br, -\b-c\bcm\bmi\bin\bn, -\b-c\bcn\bne\bew\bwe\ber\br, -\b-d\bde\bel\ble\bet\bte\be, -\b-e\bem\bmp\bpt\bty\by, -\b-f\bfs\bst\bty\byp\bpe\be, -\b-i\bin\bna\bam\bme\be, -\b-i\bin\bnu\bum\bm,\r\n", + " -\b-i\bir\bre\beg\bge\bex\bx, -\b-l\bls\bs, -\b-m\bma\bax\bxd\bde\bep\bpt\bth\bh, -\b-m\bmi\bin\bnd\bde\bep\bpt\bth\bh, -\b-m\bmm\bmi\bin\bn, -\b-p\bpa\bat\bth\bh, -\b-p\bpr\bri\bin\bnt\bt0\b0, -\b-r\bre\beg\bge\bex\bx and all\r\n", + " of the -\b-B\bB*\b* birthtime related primaries are extensions to IEEE Std\r\n", + " 1003.1-2001 (``POSIX.1'').\r\n", + "\r\n", + " Historically, the -\b-d\bd, -\b-L\bL and -\b-x\bx options were implemented using the pri-\r\n", + " maries -\b-d\bde\bep\bpt\bth\bh, -\b-f\bfo\bol\bll\blo\bow\bw, and -\b-x\bxd\bde\bev\bv. These primaries always evaluated to\r\n", + " true. As they were really global variables that took effect before the\r\n", + " traversal began, some legal expressions could have unexpected results.\r\n", + " An example is the expression -\b-p\bpr\bri\bin\bnt\bt -\b-o\bo -\b-d\bde\bep\bpt\bth\bh. As -\b-p\bpr\bri\bin\bnt\bt always evalu-\r\n", + " ates to true, the standard order of evaluation implies that -\b-d\bde\bep\bpt\bth\bh would\r\n", + " never be evaluated. This is not the case.\r\n", + "\r\n", + " The operator -\b-o\bor\br was implemented as -\b-o\bo, and the operator -\b-a\ban\bnd\bd was imple-\r\n", + " mented as -\b-a\ba.\r\n", + "\r\n", + " Historic implementations of the -\b-e\bex\bxe\bec\bc and -\b-o\bok\bk primaries did not replace\r\n", + " the string ``{}'' in the utility name or the utility arguments if it had\r\n", + " preceding or following non-whitespace characters. This version replaces\r\n", + " it no matter where in the utility name or arguments it appears.\r\n", + "\r\n", + " The -\b-E\bE option was inspired by the equivalent grep(1) and sed(1) options.\r\n", + "\r\n", + "H\bHI\bIS\bST\bTO\bOR\bRY\bY\r\n", + " A f\bfi\bin\bnd\bd command appeared in Version 1 AT&T UNIX.\r\n", + "\r\n", + "B\bBU\bUG\bGS\bS\r\n", + " The special characters used by f\bfi\bin\bnd\bd are also special characters to many\r\n", + " shell programs. In particular, the characters ``*'', ``['', ``]'',\r\n", + " ``?'', ``('', ``)'', ``!'', ``\\'' and ``;'' may have to be escaped from\r\n", + " the shell.\r\n", + "\r\n", + " As there is no delimiter separating options and file names or file names\r\n", + " and the _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn, it is difficult to specify files named _\b-_\bx_\bd_\be_\bv or _\b!.\r\n", + " These problems are handled by the -\b-f\bf option and the getopt(3) ``-\b--\b-'' con-\r\n", + " struct.\r\n", + "\r\n", + " The -\b-d\bde\bel\ble\bet\bte\be primary does not interact well with other options that cause\r\n", + " the file system tree traversal options to be changed.\r\n", + "\r\n", + " The -\b-m\bmi\bin\bnd\bde\bep\bpt\bth\bh and -\b-m\bma\bax\bxd\bde\bep\bpt\bth\bh primaries are actually global options (as\r\n", + " documented above). They should probably be replaced by options which\r\n", + " look like options.\r\n", + "\r\n", + "BSD September 28, 2011 BSD\r\n" + ] + } + ], + "source": [ + "!man find" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "参考:\n", + "- [find命令](https://man.linuxde.net/find)" + ] + } + ], + "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.6" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/notebook/common/get_class_method_name.ipynb b/notebook/common/get_class_method_name.ipynb new file mode 100644 index 0000000..ab1a610 --- /dev/null +++ b/notebook/common/get_class_method_name.ipynb @@ -0,0 +1,78 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Name\n", + "get_method_name_by_inspect\n", + "get_method_name_by_inspect\n", + "get_method_name_by_sys\n", + "\n" + ] + } + ], + "source": [ + "'''\n", + "几种获取方法名的方式\n", + "'''\n", + "import sys\n", + "import inspect\n", + "class Name():\n", + " \n", + " def get_method_name_by_sys(self):\n", + " '''使用 sys 获取方法名'''\n", + " return sys._getframe().f_code.co_name\n", + " \n", + " def get_class_name(self):\n", + " '''获取 class 名'''\n", + " return self.__class__.__name__\n", + " \n", + " def get_method_name_by_inspect(self):\n", + " '''获取当前方法名'''\n", + " print(self.get_run_method_name_by_inspect())\n", + " return inspect.stack()[0][3]\n", + " \n", + " def get_run_method_name_by_inspect(self):\n", + " '''\n", + " 通过运行在其他方法中,并获取其方法名\n", + " '''\n", + " return inspect.stack()[1][3]\n", + " \n", + " \n", + "if __name__ == \"__main__\":\n", + " n = Name()\n", + " for k in dir(n):\n", + " if not k.startswith('get_'):\n", + " continue\n", + " print(getattr(n, k)())" + ] + } + ], + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/notebook/config.py b/notebook/config.py index b47accf..6def033 100644 --- a/notebook/config.py +++ b/notebook/config.py @@ -3,4 +3,7 @@ # Author: wxnacy(wxnacy@gmail.com) # Description: -DATABASE_URL = 'mysql://root:wxnacy@127.0.0.1:3306/study?charset=utf8mb4' \ No newline at end of file +DATABASE_URL = 'mysql://root:wxnacy@127.0.0.1:3306/study?charset=utf8mb4' + +MAX = 2 ** 31 - 1 +MIN = -2 ** 31 \ No newline at end of file diff --git a/notebook/create_index.py b/notebook/create_index.py index 3e33aa7..6036d52 100644 --- a/notebook/create_index.py +++ b/notebook/create_index.py @@ -24,6 +24,7 @@ import os import urllib.parse + def main(dirname): for dirname, subdirs, files in os.walk(dirname): lines = '' diff --git a/notebook/publish.sh b/notebook/deploy.sh similarity index 80% rename from notebook/publish.sh rename to notebook/deploy.sh index b391116..b976261 100755 --- a/notebook/publish.sh +++ b/notebook/deploy.sh @@ -2,7 +2,8 @@ # Author: wxnacy(wxnacy@gmail.com) # Description: -ipynb_files=`find . -name "*.ipynb" | grep -v checkpoints` +./convert.sh + for file in `find static -name "*.html"` do outfile=`python -c "print('${file}'.replace('static/', ''))"` diff --git a/notebook/docs/index.md b/notebook/docs/index.md new file mode 100644 index 0000000..000ea34 --- /dev/null +++ b/notebook/docs/index.md @@ -0,0 +1,17 @@ +# Welcome to MkDocs + +For full documentation visit [mkdocs.org](https://www.mkdocs.org). + +## Commands + +* `mkdocs new [dir-name]` - Create a new project. +* `mkdocs serve` - Start the live-reloading docs server. +* `mkdocs build` - Build the documentation site. +* `mkdocs -h` - Print help message and exit. + +## Project layout + + mkdocs.yml # The configuration file. + docs/ + index.md # The documentation homepage. + ... # Other markdown pages, images and other files. diff --git a/notebook/mkdocs.yml b/notebook/mkdocs.yml new file mode 100644 index 0000000..e325037 --- /dev/null +++ b/notebook/mkdocs.yml @@ -0,0 +1,2 @@ +site_name: Wxnacy Notebook +dev_addr: 127.0.0.1:6690 diff --git a/notebook/modules/databases/sqlalchemy.ipynb b/notebook/modules/databases/sqlalchemy.ipynb index d687962..5b1f0dd 100644 --- a/notebook/modules/databases/sqlalchemy.ipynb +++ b/notebook/modules/databases/sqlalchemy.ipynb @@ -2,7 +2,29 @@ "cells": [ { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting databases\n", + " Using cached databases-0.3.2-py3-none-any.whl (18 kB)\n", + "Requirement already satisfied: sqlalchemy in /Users/wxnacy/.pyenv/versions/3.7.6/envs/notebook/lib/python3.7/site-packages (from databases) (1.3.17)\n", + "Installing collected packages: databases\n", + "Successfully installed databases-0.3.2\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install databases" + ] + }, + { + "cell_type": "code", + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -28,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -203,7 +225,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -212,7 +234,7 @@ "[(1, 'Daisy', 92)]" ] }, - "execution_count": 10, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -223,6 +245,199 @@ "await database.fetch_all(query=query)" ] }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on method where in module sqlalchemy.sql.selectable:\n", + "\n", + "where(whereclause) method of sqlalchemy.sql.selectable.Select instance\n", + " return a new select() construct with the given expression added to\n", + " its WHERE clause, joined to the existing clause via AND, if any.\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "[(1, 'Daisy', 92)]" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "help(user.select().where)\n", + "\n", + "query = user.select().where(text(\"id = 1\"))\n", + "await database.fetch_all(query=query)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['__and__',\n", + " '__bool__',\n", + " '__class__',\n", + " '__delattr__',\n", + " '__dict__',\n", + " '__dir__',\n", + " '__doc__',\n", + " '__eq__',\n", + " '__format__',\n", + " '__ge__',\n", + " '__getattribute__',\n", + " '__getstate__',\n", + " '__gt__',\n", + " '__hash__',\n", + " '__init__',\n", + " '__init_subclass__',\n", + " '__invert__',\n", + " '__le__',\n", + " '__lt__',\n", + " '__module__',\n", + " '__ne__',\n", + " '__new__',\n", + " '__nonzero__',\n", + " '__or__',\n", + " '__reduce__',\n", + " '__reduce_ex__',\n", + " '__repr__',\n", + " '__setattr__',\n", + " '__sizeof__',\n", + " '__str__',\n", + " '__subclasshook__',\n", + " '__visit_name__',\n", + " '__weakref__',\n", + " '_annotate',\n", + " '_annotations',\n", + " '_autoincrement_column',\n", + " '_autoload',\n", + " '_clone',\n", + " '_cloned_set',\n", + " '_cols_populated',\n", + " '_columns',\n", + " '_compiler',\n", + " '_compiler_dispatch',\n", + " '_constructor',\n", + " '_copy_internals',\n", + " '_deannotate',\n", + " '_execute_on_connection',\n", + " '_extra_dependencies',\n", + " '_extra_kwargs',\n", + " '_from_objects',\n", + " '_hide_froms',\n", + " '_init',\n", + " '_init_collections',\n", + " '_init_existing',\n", + " '_init_items',\n", + " '_is_clone_of',\n", + " '_is_from_container',\n", + " '_is_join',\n", + " '_is_lateral',\n", + " '_is_lexical_equivalent',\n", + " '_is_select',\n", + " '_kw_reg_for_dialect',\n", + " '_kw_reg_for_dialect_cls',\n", + " '_kw_registry',\n", + " '_memoized_property',\n", + " '_negate',\n", + " '_order_by_label_element',\n", + " '_params',\n", + " '_populate_column_collection',\n", + " '_prefixes',\n", + " '_refresh_for_new_column',\n", + " '_reset_exported',\n", + " '_schema_item_copy',\n", + " '_select_iterable',\n", + " '_set_parent',\n", + " '_set_parent_with_dispatch',\n", + " '_sorted_constraints',\n", + " '_textual',\n", + " '_translate_schema',\n", + " '_validate_dialect_kwargs',\n", + " '_with_annotations',\n", + " 'add_is_dependent_on',\n", + " 'alias',\n", + " 'append_column',\n", + " 'append_constraint',\n", + " 'append_ddl_listener',\n", + " 'argument_for',\n", + " 'bind',\n", + " 'c',\n", + " 'columns',\n", + " 'comment',\n", + " 'compare',\n", + " 'compile',\n", + " 'constraints',\n", + " 'correspond_on_equivalents',\n", + " 'corresponding_column',\n", + " 'count',\n", + " 'create',\n", + " 'delete',\n", + " 'description',\n", + " 'dialect_kwargs',\n", + " 'dialect_options',\n", + " 'dispatch',\n", + " 'drop',\n", + " 'exists',\n", + " 'foreign_key_constraints',\n", + " 'foreign_keys',\n", + " 'fullname',\n", + " 'get_children',\n", + " 'implicit_returning',\n", + " 'indexes',\n", + " 'info',\n", + " 'insert',\n", + " 'is_clause_element',\n", + " 'is_derived_from',\n", + " 'is_selectable',\n", + " 'join',\n", + " 'key',\n", + " 'kwargs',\n", + " 'lateral',\n", + " 'metadata',\n", + " 'name',\n", + " 'named_with_column',\n", + " 'outerjoin',\n", + " 'params',\n", + " 'primary_key',\n", + " 'quote',\n", + " 'quote_schema',\n", + " 'replace_selectable',\n", + " 'schema',\n", + " 'select',\n", + " 'selectable',\n", + " 'self_group',\n", + " 'supports_execution',\n", + " 'tablesample',\n", + " 'tometadata',\n", + " 'unique_params',\n", + " 'update']" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 查看 user 属性\n", + "dir(user)" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/notebook/static/commands/find.html b/notebook/static/commands/find.html new file mode 100644 index 0000000..fbc6588 --- /dev/null +++ b/notebook/static/commands/find.html @@ -0,0 +1,14151 @@ + + + + +find + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
In [28]:
+
+
+
# 查找当前目录及子目录下所有文件
+!find .
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
.
+./find.ipynb
+./.ipynb_checkpoints
+./.ipynb_checkpoints/find-checkpoint.ipynb
+
+
+
+ +
+
+ +
+
+
+
In [29]:
+
+
+
# 查找当前目录及子目录下所有 .ipynb 后缀的文件
+!find . -name "*.ipynb"
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
./find.ipynb
+./.ipynb_checkpoints/find-checkpoint.ipynb
+
+
+
+ +
+
+ +
+
+
+
In [30]:
+
+
+
# 忽略大小写
+!find . -iname "*.ipynb"
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
./find.ipynb
+./.ipynb_checkpoints/find-checkpoint.ipynb
+
+
+
+ +
+
+ +
+
+
+
In [20]:
+
+
+
# 查找当前目录及子目录下所有不是 .ipynb 后缀的文件
+!find . ! -name "*.ipynb"
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
.
+./.ipynb_checkpoints
+
+
+
+ +
+
+ +
+
+
+
In [22]:
+
+
+
# 向下查找 1 层深度
+!find . -maxdepth 1 
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
.
+./Untitled.ipynb
+./.ipynb_checkpoints
+
+
+
+ +
+
+ +
+
+
+
In [32]:
+
+
+
# 根据文件类型进行搜索
+!find . -type f
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
./find.ipynb
+./.ipynb_checkpoints/find-checkpoint.ipynb
+
+
+
+ +
+
+ +
+
+
+
+

类型参数列表:

+
    +
  • f 普通文件
  • +
  • l 符号连接
  • +
  • d 目录
  • +
  • c 字符设备
  • +
  • b 块设备
  • +
  • s 套接字
  • +
  • p Fifo
  • +
+ +
+
+
+
+
+
In [39]:
+
+
+
# 查找上层目录并多匹配
+!find .. -name "*.py" -o -name "*.pdf"
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
../config.py
+../create_index.py
+
+
+
+ +
+
+ +
+
+
+
In [42]:
+
+
+
# 匹配文件路径或者文件
+!find . -path "*ipynb*"
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
./find.ipynb
+./.ipynb_checkpoints
+./.ipynb_checkpoints/find-checkpoint.ipynb
+
+
+
+ +
+
+ +
+
+
+
In [50]:
+
+
+
# 基于正则表达式匹配文件路径
+!find . -regex ".*ipynb"
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
./find.ipynb
+./.ipynb_checkpoints/find-checkpoint.ipynb
+
+
+
+ +
+
+ +
+
+
+
In [54]:
+
+
+
# 搜索大于 1k 的文件
+!find . -type f -size +1k
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
./find.ipynb
+./.ipynb_checkpoints/find-checkpoint.ipynb
+
+
+
+ +
+
+ +
+
+
+
In [62]:
+
+
+
# 搜索小于 100k 的文件
+!find . -type f -size -100k
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
./find.ipynb
+./.ipynb_checkpoints/find-checkpoint.ipynb
+
+
+
+ +
+
+ +
+
+
+
In [64]:
+
+
+
# 搜索等于 100k 的文件
+!find . -type f -size 100k
+
+ +
+
+
+ +
+
+
+
+

文件大小单元:

+
    +
  • b —— 块(512字节)
  • +
  • c —— 字节
  • +
  • w —— 字(2字节)
  • +
  • k —— 千字节
  • +
  • M —— 兆字节
  • +
  • G —— 吉字节
  • +
+ +
+
+
+
+
+
In [31]:
+
+
+
!man find
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
+FIND(1)                   BSD General Commands Manual                  FIND(1)
+
+NNAAMMEE
+     ffiinndd -- walk a file hierarchy
+
+SSYYNNOOPPSSIISS
+     ffiinndd [--HH | --LL | --PP] [--EEXXddssxx] [--ff _p_a_t_h] _p_a_t_h _._._. [_e_x_p_r_e_s_s_i_o_n]
+     ffiinndd [--HH | --LL | --PP] [--EEXXddssxx] --ff _p_a_t_h [_p_a_t_h _._._.] [_e_x_p_r_e_s_s_i_o_n]
+
+DDEESSCCRRIIPPTTIIOONN
+     The ffiinndd utility recursively descends the directory tree for each _p_a_t_h
+     listed, evaluating an _e_x_p_r_e_s_s_i_o_n (composed of the ``primaries'' and
+     ``operands'' listed below) in terms of each file in the tree.
+
+     The options are as follows:
+
+     --EE      Interpret regular expressions followed by --rreeggeexx and --iirreeggeexx pri-
+             maries as extended (modern) regular expressions rather than basic
+             regular expressions (BRE's).  The re_format(7) manual page fully
+             describes both formats.
+
+     --HH      Cause the file information and file type (see stat(2)) returned
+             for each symbolic link specified on the command line to be those
+             of the file referenced by the link, not the link itself.  If the
+             referenced file does not exist, the file information and type
+             will be for the link itself.  File information of all symbolic
+             links not on the command line is that of the link itself.
+
+     --LL      Cause the file information and file type (see stat(2)) returned
+             for each symbolic link to be those of the file referenced by the
+             link, not the link itself.  If the referenced file does not
+             exist, the file information and type will be for the link itself.
+
+             This option is equivalent to the deprecated --ffoollllooww primary.
+
+     --PP      Cause the file information and file type (see stat(2)) returned
+             for each symbolic link to be those of the link itself.  This is
+             the default.
+
+     --XX      Permit ffiinndd to be safely used in conjunction with xargs(1).  If a
+             file name contains any of the delimiting characters used by
+             xargs(1), a diagnostic message is displayed on standard error,
+             and the file is skipped.  The delimiting characters include sin-
+             gle (`` ' '') and double (`` " '') quotes, backslash (``\''),
+             space, tab and newline characters.
+
+             However, you may wish to consider the --pprriinntt00 primary in conjunc-
+             tion with ``xxaarrggss --00'' as an effective alternative.
+
+     --dd      Cause ffiinndd to perform a depth-first traversal, i.e., directories
+             are visited in post-order and all entries in a directory will be
+             acted on before the directory itself.  By default, ffiinndd visits
+             directories in pre-order, i.e., before their contents.  Note, the
+             default is _n_o_t a breadth-first traversal.
+
+             This option is equivalent to the --ddeepptthh primary of IEEE Std
+             1003.1-2001 (``POSIX.1'').  The --dd option can be useful when ffiinndd
+             is used with cpio(1) to process files that are contained in
+             directories with unusual permissions.  It ensures that you have
+             write permission while you are placing files in a directory, then
+             sets the directory's permissions as the last thing.
+
+     --ff      Specify a file hierarchy for ffiinndd to traverse.  File hierarchies
+             may also be specified as the operands immediately following the
+             options.
+
+     --ss      Cause ffiinndd to traverse the file hierarchies in lexicographical
+             order, i.e., alphabetical order within each directory.  Note:
+             `find -s' and `find | sort' may give different results.
+
+     --xx      Prevent ffiinndd from descending into directories that have a device
+             number different than that of the file from which the descent
+             began.
+
+             This option is equivalent to the deprecated --xxddeevv primary.
+
+PPRRIIMMAARRIIEESS
+     All primaries which take a numeric argument allow the number to be pre-
+     ceded by a plus sign (``+'') or a minus sign (``-'').  A preceding plus
+     sign means ``more than n'', a preceding minus sign means ``less than n''
+     and neither means ``exactly n''.
+
+     --BBmmiinn _n
+             True if the difference between the time of a file's inode cre-
+             ation and the time ffiinndd was started, rounded up to the next full
+             minute, is _n minutes.
+
+     --BBnneewweerr _f_i_l_e
+             Same as --nneewweerrBBmm.
+
+     --BBttiimmee _n[ssmmhhddww]
+             If no units are specified, this primary evaluates to true if the
+             difference between the time of a file's inode creation and the
+             time ffiinndd was started, rounded up to the next full 24-hour
+             period, is _n 24-hour periods.
+
+             If units are specified, this primary evaluates to true if the
+             difference between the time of a file's inode creation and the
+             time ffiinndd was started is exactly _n units.  Please refer to the
+             --aattiimmee primary description for information on supported time
+             units.
+
+     --aaccll    May be used in conjunction with other primaries to locate files
+             with extended ACLs.  See acl(3) for more information.
+
+     --aammiinn _n
+             True if the difference between the file last access time and the
+             time ffiinndd was started, rounded up to the next full minute, is _n
+             minutes.
+
+     --aanneewweerr _f_i_l_e
+             Same as --nneewweerraamm.
+
+     --aattiimmee _n[ssmmhhddww]
+             If no units are specified, this primary evaluates to true if the
+             difference between the file last access time and the time ffiinndd
+             was started, rounded up to the next full 24-hour period, is _n
+             24-hour periods.
+
+             If units are specified, this primary evaluates to true if the
+             difference between the file last access time and the time ffiinndd
+             was started is exactly _n units.  Possible time units are as fol-
+             lows:
+
+             ss       second
+             mm       minute (60 seconds)
+             hh       hour (60 minutes)
+             dd       day (24 hours)
+             ww       week (7 days)
+
+             Any number of units may be combined in one --aattiimmee argument, for
+             example, ``-atime -1h30m''.  Units are probably only useful when
+             used in conjunction with the ++ or -- modifier.
+
+     --ccmmiinn _n
+             True if the difference between the time of last change of file
+             status information and the time ffiinndd was started, rounded up to
+             the next full minute, is _n minutes.
+
+     --ccnneewweerr _f_i_l_e
+             Same as --nneewweerrccmm.
+
+     --ccttiimmee _n[ssmmhhddww]
+             If no units are specified, this primary evaluates to true if the
+             difference between the time of last change of file status infor-
+             mation and the time ffiinndd was started, rounded up to the next full
+             24-hour period, is _n 24-hour periods.
+
+             If units are specified, this primary evaluates to true if the
+             difference between the time of last change of file status infor-
+             mation and the time ffiinndd was started is exactly _n units.  Please
+             refer to the --aattiimmee primary description for information on sup-
+             ported time units.
+
+     --dd      Same as ddeepptthh.  GNU find implements this as a primary in mistaken
+             emulation of FreeBSD find(1).
+
+     --ddeelleettee
+             Delete found files and/or directories.  Always returns true.
+             This executes from the current working directory as ffiinndd recurses
+             down the tree.  It will not attempt to delete a filename with a
+             ``_/'' character in its pathname relative to ``_.'' for security
+             reasons.  Depth-first traversal processing is implied by this
+             option.  Following symlinks is incompatible with this option.
+
+     --ddeepptthh  Always true; same as the --dd option.
+
+     --ddeepptthh _n
+             True if the depth of the file relative to the starting point of
+             the traversal is _n.
+
+     --eemmppttyy  True if the current file or directory is empty.
+
+     --eexxeecc _u_t_i_l_i_t_y [_a_r_g_u_m_e_n_t _._._.] ;
+             True if the program named _u_t_i_l_i_t_y returns a zero value as its
+             exit status.  Optional _a_r_g_u_m_e_n_t_s may be passed to the utility.
+             The expression must be terminated by a semicolon (``;'').  If you
+             invoke ffiinndd from a shell you may need to quote the semicolon if
+             the shell would otherwise treat it as a control operator.  If the
+             string ``{}'' appears anywhere in the utility name or the argu-
+             ments it is replaced by the pathname of the current file.
+             _U_t_i_l_i_t_y will be executed from the directory from which ffiinndd was
+             executed.  _U_t_i_l_i_t_y and _a_r_g_u_m_e_n_t_s are not subject to the further
+             expansion of shell patterns and constructs.
+
+     --eexxeecc _u_t_i_l_i_t_y [_a_r_g_u_m_e_n_t _._._.] {} +
+             Same as --eexxeecc, except that ``{}'' is replaced with as many path-
+             names as possible for each invocation of _u_t_i_l_i_t_y.  This behaviour
+             is similar to that of xargs(1).
+
+     --eexxeeccddiirr _u_t_i_l_i_t_y [_a_r_g_u_m_e_n_t _._._.] ;
+             The --eexxeeccddiirr primary is identical to the --eexxeecc primary with the
+             exception that _u_t_i_l_i_t_y will be executed from the directory that
+             holds the current file.  The filename substituted for the string
+             ``{}'' is not qualified.
+
+     --eexxeeccddiirr _u_t_i_l_i_t_y [_a_r_g_u_m_e_n_t _._._.] {} +
+             Same as --eexxeeccddiirr, except that ``{}'' is replaced with as many
+             pathnames as possible for each invocation of _u_t_i_l_i_t_y.  This be-
+             haviour is similar to that of xargs(1).
+
+     --ffllaaggss [--|++]_f_l_a_g_s,_n_o_t_f_l_a_g_s
+             The flags are specified using symbolic names (see chflags(1)).
+             Those with the "no" prefix (except "nodump") are said to be
+             _n_o_t_f_l_a_g_s.  Flags in _f_l_a_g_s are checked to be set, and flags in
+             _n_o_t_f_l_a_g_s are checked to be not set.  Note that this is different
+             from --ppeerrmm, which only allows the user to specify mode bits that
+             are set.
+
+             If flags are preceded by a dash (``-''), this primary evaluates
+             to true if at least all of the bits in _f_l_a_g_s and none of the bits
+             in _n_o_t_f_l_a_g_s are set in the file's flags bits.  If flags are pre-
+             ceded by a plus (``+''), this primary evaluates to true if any of
+             the bits in _f_l_a_g_s is set in the file's flags bits, or any of the
+             bits in _n_o_t_f_l_a_g_s is not set in the file's flags bits.  Otherwise,
+             this primary evaluates to true if the bits in _f_l_a_g_s exactly match
+             the file's flags bits, and none of the _f_l_a_g_s bits match those of
+             _n_o_t_f_l_a_g_s.
+
+     --ffssttyyppee _t_y_p_e
+             True if the file is contained in a file system of type _t_y_p_e.  The
+             lsvfs(1) command can be used to find out the types of file sys-
+             tems that are available on the system.  In addition, there are
+             two pseudo-types, ``local'' and ``rdonly''.  The former matches
+             any file system physically mounted on the system where the ffiinndd
+             is being executed and the latter matches any file system which is
+             mounted read-only.
+
+     --ggiidd _g_n_a_m_e
+             The same thing as _-_g_r_o_u_p _g_n_a_m_e for compatibility with GNU find.
+             GNU find imposes a restriction that _g_n_a_m_e is numeric, while
+             find(1) does not.
+
+     --ggrroouupp _g_n_a_m_e
+             True if the file belongs to the group _g_n_a_m_e.  If _g_n_a_m_e is numeric
+             and there is no such group name, then _g_n_a_m_e is treated as a group
+             ID.
+
+     --iiggnnoorree__rreeaaddddiirr__rraaccee
+             This option is for GNU find compatibility and is ignored.
+
+     --iillnnaammee _p_a_t_t_e_r_n
+             Like --llnnaammee, but the match is case insensitive.  This is a GNU
+             find extension.
+
+     --iinnaammee _p_a_t_t_e_r_n
+             Like --nnaammee, but the match is case insensitive.
+
+     --iinnuumm _n
+             True if the file has inode number _n.
+
+     --iippaatthh _p_a_t_t_e_r_n
+             Like --ppaatthh, but the match is case insensitive.
+
+     --iirreeggeexx _p_a_t_t_e_r_n
+             Like --rreeggeexx, but the match is case insensitive.
+
+     --iiwwhhoolleennaammee _p_a_t_t_e_r_n
+             The same thing as --iippaatthh, for GNU find compatibility.
+
+     --lliinnkkss _n
+             True if the file has _n links.
+
+     --llnnaammee _p_a_t_t_e_r_n
+             Like --nnaammee, but the contents of the symbolic link are matched
+             instead of the file name.  Note that this only matches broken
+             symbolic links if symbolic links are being followed.  This is a
+             GNU find extension.
+
+     --llss     This primary always evaluates to true.  The following information
+             for the current file is written to standard output: its inode
+             number, size in 512-byte blocks, file permissions, number of hard
+             links, owner, group, size in bytes, last modification time, and
+             pathname.  If the file is a block or character special file, the
+             device number will be displayed instead of the size in bytes.  If
+             the file is a symbolic link, the pathname of the linked-to file
+             will be displayed preceded by ``->''.  The format is identical to
+             that produced by ``llss --ddggiillss''.
+
+     --mmaaxxddeepptthh _n
+             Always true; descend at most _n directory levels below the command
+             line arguments.  If any --mmaaxxddeepptthh primary is specified, it
+             applies to the entire expression even if it would not normally be
+             evaluated.  ``--mmaaxxddeepptthh 0'' limits the whole search to the com-
+             mand line arguments.
+
+     --mmiinnddeepptthh _n
+             Always true; do not apply any tests or actions at levels less
+             than _n.  If any --mmiinnddeepptthh primary is specified, it applies to the
+             entire expression even if it would not normally be evaluated.
+             ``--mmiinnddeepptthh 1'' processes all but the command line arguments.
+
+     --mmmmiinn _n
+             True if the difference between the file last modification time
+             and the time ffiinndd was started, rounded up to the next full
+             minute, is _n minutes.
+
+     --mmnneewweerr _f_i_l_e
+             Same as --nneewweerr.
+
+     --mmoouunntt  The same thing as --xxddeevv, for GNU find compatibility.
+
+     --mmttiimmee _n[ssmmhhddww]
+             If no units are specified, this primary evaluates to true if the
+             difference between the file last modification time and the time
+             ffiinndd was started, rounded up to the next full 24-hour period, is
+             _n 24-hour periods.
+
+             If units are specified, this primary evaluates to true if the
+             difference between the file last modification time and the time
+             ffiinndd was started is exactly _n units.  Please refer to the --aattiimmee
+             primary description for information on supported time units.
+
+     --nnaammee _p_a_t_t_e_r_n
+             True if the last component of the pathname being examined matches
+             _p_a_t_t_e_r_n.  Special shell pattern matching characters (``['',
+             ``]'', ``*'', and ``?'') may be used as part of _p_a_t_t_e_r_n.  These
+             characters may be matched explicitly by escaping them with a
+             backslash (``\'').
+
+     --nneewweerr _f_i_l_e
+             True if the current file has a more recent last modification time
+             than _f_i_l_e.
+
+     --nneewweerr_X_Y _f_i_l_e
+             True if the current file has a more recent last access time
+             (_X=aa), inode creation time (_X=BB), change time (_X=cc), or modifica-
+             tion time (_X=mm) than the last access time (_Y=aa), inode creation
+             time (_Y=BB), change time (_Y=cc), or modification time (_Y=mm) of
+             _f_i_l_e.  In addition, if _Y=tt, then _f_i_l_e is instead interpreted as a
+             direct date specification of the form understood by cvs(1).  Note
+             that --nneewweerrmmmm is equivalent to --nneewweerr.
+
+     --nnooggrroouupp
+             True if the file belongs to an unknown group.
+
+     --nnooiiggnnoorree__rreeaaddddiirr__rraaccee
+             This option is for GNU find compatibility and is ignored.
+
+     --nnoolleeaaff
+             This option is for GNU find compatibility.  In GNU find it dis-
+             ables an optimization not relevant to find(1), so it is ignored.
+
+     --nnoouusseerr
+             True if the file belongs to an unknown user.
+
+     --ookk _u_t_i_l_i_t_y [_a_r_g_u_m_e_n_t _._._.] ;
+             The --ookk primary is identical to the --eexxeecc primary with the excep-
+             tion that ffiinndd requests user affirmation for the execution of the
+             _u_t_i_l_i_t_y by printing a message to the terminal and reading a
+             response.  If the response is not affirmative (`y' in the
+             ``POSIX'' locale), the command is not executed and the value of
+             the --ookk expression is false.
+
+     --ookkddiirr _u_t_i_l_i_t_y [_a_r_g_u_m_e_n_t _._._.] ;
+             The --ookkddiirr primary is identical to the --eexxeeccddiirr primary with the
+             same exception as described for the --ookk primary.
+
+     --ppaatthh _p_a_t_t_e_r_n
+             True if the pathname being examined matches _p_a_t_t_e_r_n.  Special
+             shell pattern matching characters (``['', ``]'', ``*'', and
+             ``?'') may be used as part of _p_a_t_t_e_r_n.  These characters may be
+             matched explicitly by escaping them with a backslash (``\'').
+             Slashes (``/'') are treated as normal characters and do not have
+             to be matched explicitly.
+
+     --ppeerrmm [--|++]_m_o_d_e
+             The _m_o_d_e may be either symbolic (see chmod(1)) or an octal num-
+             ber.  If the _m_o_d_e is symbolic, a starting value of zero is
+             assumed and the _m_o_d_e sets or clears permissions without regard to
+             the process' file mode creation mask.  If the _m_o_d_e is octal, only
+             bits 07777 (S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG |
+             S_IRWXO) of the file's mode bits participate in the comparison.
+             If the _m_o_d_e is preceded by a dash (``-''), this primary evaluates
+             to true if at least all of the bits in the _m_o_d_e are set in the
+             file's mode bits.  If the _m_o_d_e is preceded by a plus (``+''),
+             this primary evaluates to true if any of the bits in the _m_o_d_e are
+             set in the file's mode bits.  Otherwise, this primary evaluates
+             to true if the bits in the _m_o_d_e exactly match the file's mode
+             bits.  Note, the first character of a symbolic mode may not be a
+             dash (``-'').
+
+     --pprriinntt  This primary always evaluates to true.  It prints the pathname of
+             the current file to standard output.  If none of --eexxeecc, --llss,
+             --pprriinntt, --pprriinntt00, or --ookk is specified, the given expression shall
+             be effectively replaced by (( _g_i_v_e_n _e_x_p_r_e_s_s_i_o_n )) --pprriinntt.
+
+     --pprriinntt00
+             This primary always evaluates to true.  It prints the pathname of
+             the current file to standard output, followed by an ASCII NUL
+             character (character code 0).
+
+     --pprruunnee  This primary always evaluates to true.  It causes ffiinndd to not
+             descend into the current file.  Note, the --pprruunnee primary has no
+             effect if the --dd option was specified.
+
+     --rreeggeexx _p_a_t_t_e_r_n
+             True if the whole path of the file matches _p_a_t_t_e_r_n using regular
+             expression.  To match a file named ``_._/_f_o_o_/_x_y_z_z_y'', you can use
+             the regular expression ``.*/[xyz]*'' or ``.*/foo/.*'', but not
+             ``xyzzy'' or ``/foo/''.
+
+     --ssaammeeffiillee _n_a_m_e
+             True if the file is a hard link to _n_a_m_e.  If the command option
+             --LL is specified, it is also true if the file is a symbolic link
+             and points to _n_a_m_e.
+
+     --ssiizzee _n[cckkMMGGTTPP]
+             True if the file's size, rounded up, in 512-byte blocks is _n.  If
+             _n is followed by a cc, then the primary is true if the file's size
+             is _n bytes (characters).  Similarly if _n is followed by a scale
+             indicator then the file's size is compared to _n scaled as:
+
+             kk       kilobytes (1024 bytes)
+             MM       megabytes (1024 kilobytes)
+             GG       gigabytes (1024 megabytes)
+             TT       terabytes (1024 gigabytes)
+             PP       petabytes (1024 terabytes)
+
+     --ttyyppee _t
+             True if the file is of the specified type.  Possible file types
+             are as follows:
+
+             bb       block special
+             cc       character special
+             dd       directory
+             ff       regular file
+             ll       symbolic link
+             pp       FIFO
+             ss       socket
+
+     --uuiidd _u_n_a_m_e
+             The same thing as _-_u_s_e_r _u_n_a_m_e for compatibility with GNU find.
+             GNU find imposes a restriction that _u_n_a_m_e is numeric, while
+             find(1) does not.
+
+     --uusseerr _u_n_a_m_e
+             True if the file belongs to the user _u_n_a_m_e.  If _u_n_a_m_e is numeric
+             and there is no such user name, then _u_n_a_m_e is treated as a user
+             ID.
+
+     --wwhhoolleennaammee _p_a_t_t_e_r_n
+             The same thing as --ppaatthh, for GNU find compatibility.
+
+     --xxaattttrr  True if the file has any extended attributes.
+
+     --xxaattttrrnnaammee _n_a_m_e
+             True if the file has an extended attribute with the specified
+             _n_a_m_e.
+
+OOPPEERRAATTOORRSS
+     The primaries may be combined using the following operators.  The opera-
+     tors are listed in order of decreasing precedence.
+
+     (( _e_x_p_r_e_s_s_i_o_n ))
+             This evaluates to true if the parenthesized expression evaluates
+             to true.
+
+     !! _e_x_p_r_e_s_s_i_o_n
+     --nnoott _e_x_p_r_e_s_s_i_o_n
+             This is the unary NOT operator.  It evaluates to true if the
+             expression is false.
+
+     --ffaallssee  Always false.
+     --ttrruuee   Always true.
+
+     _e_x_p_r_e_s_s_i_o_n --aanndd _e_x_p_r_e_s_s_i_o_n
+     _e_x_p_r_e_s_s_i_o_n _e_x_p_r_e_s_s_i_o_n
+             The --aanndd operator is the logical AND operator.  As it is implied
+             by the juxtaposition of two expressions it does not have to be
+             specified.  The expression evaluates to true if both expressions
+             are true.  The second expression is not evaluated if the first
+             expression is false.
+
+     _e_x_p_r_e_s_s_i_o_n --oorr _e_x_p_r_e_s_s_i_o_n
+             The --oorr operator is the logical OR operator.  The expression
+             evaluates to true if either the first or the second expression is
+             true.  The second expression is not evaluated if the first
+             expression is true.
+
+     All operands and primaries must be separate arguments to ffiinndd.  Primaries
+     which themselves take arguments expect each argument to be a separate
+     argument to ffiinndd.
+
+EENNVVIIRROONNMMEENNTT
+     The LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES and LC_TIME environ-
+     ment variables affect the execution of the ffiinndd utility as described in
+     environ(7).
+
+EEXXAAMMPPLLEESS
+     The following examples are shown as given to the shell:
+
+     find / \! -name "*.c" -print
+             Print out a list of all the files whose names do not end in _._c.
+
+     find / -newer ttt -user wnj -print
+             Print out a list of all the files owned by user ``wnj'' that are
+             newer than the file _t_t_t.
+
+     find / \! \( -newer ttt -user wnj \) -print
+             Print out a list of all the files which are not both newer than
+             _t_t_t and owned by ``wnj''.
+
+     find / \( -newer ttt -or -user wnj \) -print
+             Print out a list of all the files that are either owned by
+             ``wnj'' or that are newer than _t_t_t.
+
+     find / -newerct '1 minute ago' -print
+             Print out a list of all the files whose inode change time is more
+             recent than the current time minus one minute.
+
+     find / -type f -exec echo {} \;
+             Use the echo(1) command to print out a list of all the files.
+
+     find -L /usr/ports/packages -type l -exec rm -- {} +
+             Delete all broken symbolic links in _/_u_s_r_/_p_o_r_t_s_/_p_a_c_k_a_g_e_s.
+
+     find /usr/src -name CVS -prune -o -depth +6 -print
+             Find files and directories that are at least seven levels deep in
+             the working directory _/_u_s_r_/_s_r_c.
+
+     find /usr/src -name CVS -prune -o -mindepth 7 -print
+             Is not equivalent to the previous example, since --pprruunnee is not
+             evaluated below level seven.
+
+CCOOMMPPAATTIIBBIILLIITTYY
+     The --ffoollllooww primary is deprecated; the --LL option should be used instead.
+     See the _S_T_A_N_D_A_R_D_S section below for details.
+
+SSEEEE AALLSSOO
+     chflags(1), chmod(1), cvs(1), locate(1), lsvfs(1), whereis(1), which(1),
+     xargs(1), stat(2), acl(3), fts(3), getgrent(3), getpwent(3), strmode(3),
+
+
+SSTTAANNDDAARRDDSS
+     The ffiinndd utility syntax is a superset of the syntax specified by the IEEE
+     Std 1003.1-2001 (``POSIX.1'') standard.
+
+     All the single character options except --HH and --LL as well as --aammiinn,
+     --aanneewweerr, --ccmmiinn, --ccnneewweerr, --ddeelleettee, --eemmppttyy, --ffssttyyppee, --iinnaammee, --iinnuumm,
+     --iirreeggeexx, --llss, --mmaaxxddeepptthh, --mmiinnddeepptthh, --mmmmiinn, --ppaatthh, --pprriinntt00, --rreeggeexx and all
+     of the --BB** birthtime related primaries are extensions to IEEE Std
+     1003.1-2001 (``POSIX.1'').
+
+     Historically, the --dd, --LL and --xx options were implemented using the pri-
+     maries --ddeepptthh, --ffoollllooww, and --xxddeevv.  These primaries always evaluated to
+     true.  As they were really global variables that took effect before the
+     traversal began, some legal expressions could have unexpected results.
+     An example is the expression --pprriinntt --oo --ddeepptthh.  As --pprriinntt always evalu-
+     ates to true, the standard order of evaluation implies that --ddeepptthh would
+     never be evaluated.  This is not the case.
+
+     The operator --oorr was implemented as --oo, and the operator --aanndd was imple-
+     mented as --aa.
+
+     Historic implementations of the --eexxeecc and --ookk primaries did not replace
+     the string ``{}'' in the utility name or the utility arguments if it had
+     preceding or following non-whitespace characters.  This version replaces
+     it no matter where in the utility name or arguments it appears.
+
+     The --EE option was inspired by the equivalent grep(1) and sed(1) options.
+
+HHIISSTTOORRYY
+     A ffiinndd command appeared in Version 1 AT&T UNIX.
+
+BBUUGGSS
+     The special characters used by ffiinndd are also special characters to many
+     shell programs.  In particular, the characters ``*'', ``['', ``]'',
+     ``?'', ``('', ``)'', ``!'', ``\'' and ``;'' may have to be escaped from
+     the shell.
+
+     As there is no delimiter separating options and file names or file names
+     and the _e_x_p_r_e_s_s_i_o_n, it is difficult to specify files named _-_x_d_e_v or _!.
+     These problems are handled by the --ff option and the getopt(3) ``----'' con-
+     struct.
+
+     The --ddeelleettee primary does not interact well with other options that cause
+     the file system tree traversal options to be changed.
+
+     The --mmiinnddeepptthh and --mmaaxxddeepptthh primaries are actually global options (as
+     documented above).  They should probably be replaced by options which
+     look like options.
+
+BSD                           September 28, 2011                           BSD
+
+
+
+ +
+
+ +
+
+
+
+

参考:

+ + +
+
+
+
+
+ + + + + + + + diff --git a/notebook/static/common/get_class_method_name.html b/notebook/static/common/get_class_method_name.html new file mode 100644 index 0000000..039d818 --- /dev/null +++ b/notebook/static/common/get_class_method_name.html @@ -0,0 +1,13151 @@ + + + + +get_class_method_name + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
In [15]:
+
+
+
'''
+几种获取方法名的方式
+'''
+import sys
+import inspect
+class Name():
+ 
+    def get_method_name_by_sys(self):
+        '''使用 sys 获取方法名'''
+        return sys._getframe().f_code.co_name
+    
+    def get_class_name(self):
+        '''获取 class 名'''
+        return self.__class__.__name__
+    
+    def get_method_name_by_inspect(self):
+        '''获取当前方法名'''
+        print(self.get_run_method_name_by_inspect())
+        return inspect.stack()[0][3]
+    
+    def get_run_method_name_by_inspect(self):
+        '''
+        通过运行在其他方法中,并获取其方法名
+        '''
+        return inspect.stack()[1][3]
+    
+ 
+if __name__ == "__main__":
+    n = Name()
+    for k in dir(n):
+        if not k.startswith('get_'):
+            continue
+        print(getattr(n, k)())
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
Name
+get_method_name_by_inspect
+get_method_name_by_inspect
+get_method_name_by_sys
+<module>
+
+
+
+ +
+
+ +
+
+
+ + + + + + diff --git a/notebook/static/modules/databases/sqlalchemy.html b/notebook/static/modules/databases/sqlalchemy.html index e8e7c45..ca7c192 100644 --- a/notebook/static/modules/databases/sqlalchemy.html +++ b/notebook/static/modules/databases/sqlalchemy.html @@ -13076,7 +13076,7 @@
-
In [5]:
+
In [2]:
# 使用 sqlalchemy 进行数据库操作
@@ -13401,6 +13401,177 @@
 
+
+
+
+
In [3]:
+
+
+
# 查看 user 属性
+dir(user)
+
+ +
+
+
+ +
+
+ + +
+ +
Out[3]:
+ + + + +
+
['__and__',
+ '__bool__',
+ '__class__',
+ '__delattr__',
+ '__dict__',
+ '__dir__',
+ '__doc__',
+ '__eq__',
+ '__format__',
+ '__ge__',
+ '__getattribute__',
+ '__getstate__',
+ '__gt__',
+ '__hash__',
+ '__init__',
+ '__init_subclass__',
+ '__invert__',
+ '__le__',
+ '__lt__',
+ '__module__',
+ '__ne__',
+ '__new__',
+ '__nonzero__',
+ '__or__',
+ '__reduce__',
+ '__reduce_ex__',
+ '__repr__',
+ '__setattr__',
+ '__sizeof__',
+ '__str__',
+ '__subclasshook__',
+ '__visit_name__',
+ '__weakref__',
+ '_annotate',
+ '_annotations',
+ '_autoincrement_column',
+ '_autoload',
+ '_clone',
+ '_cloned_set',
+ '_cols_populated',
+ '_columns',
+ '_compiler',
+ '_compiler_dispatch',
+ '_constructor',
+ '_copy_internals',
+ '_deannotate',
+ '_execute_on_connection',
+ '_extra_dependencies',
+ '_extra_kwargs',
+ '_from_objects',
+ '_hide_froms',
+ '_init',
+ '_init_collections',
+ '_init_existing',
+ '_init_items',
+ '_is_clone_of',
+ '_is_from_container',
+ '_is_join',
+ '_is_lateral',
+ '_is_lexical_equivalent',
+ '_is_select',
+ '_kw_reg_for_dialect',
+ '_kw_reg_for_dialect_cls',
+ '_kw_registry',
+ '_memoized_property',
+ '_negate',
+ '_order_by_label_element',
+ '_params',
+ '_populate_column_collection',
+ '_prefixes',
+ '_refresh_for_new_column',
+ '_reset_exported',
+ '_schema_item_copy',
+ '_select_iterable',
+ '_set_parent',
+ '_set_parent_with_dispatch',
+ '_sorted_constraints',
+ '_textual',
+ '_translate_schema',
+ '_validate_dialect_kwargs',
+ '_with_annotations',
+ 'add_is_dependent_on',
+ 'alias',
+ 'append_column',
+ 'append_constraint',
+ 'append_ddl_listener',
+ 'argument_for',
+ 'bind',
+ 'c',
+ 'columns',
+ 'comment',
+ 'compare',
+ 'compile',
+ 'constraints',
+ 'correspond_on_equivalents',
+ 'corresponding_column',
+ 'count',
+ 'create',
+ 'delete',
+ 'description',
+ 'dialect_kwargs',
+ 'dialect_options',
+ 'dispatch',
+ 'drop',
+ 'exists',
+ 'foreign_key_constraints',
+ 'foreign_keys',
+ 'fullname',
+ 'get_children',
+ 'implicit_returning',
+ 'indexes',
+ 'info',
+ 'insert',
+ 'is_clause_element',
+ 'is_derived_from',
+ 'is_selectable',
+ 'join',
+ 'key',
+ 'kwargs',
+ 'lateral',
+ 'metadata',
+ 'name',
+ 'named_with_column',
+ 'outerjoin',
+ 'params',
+ 'primary_key',
+ 'quote',
+ 'quote_schema',
+ 'replace_selectable',
+ 'schema',
+ 'select',
+ 'selectable',
+ 'self_group',
+ 'supports_execution',
+ 'tablesample',
+ 'tometadata',
+ 'unique_params',
+ 'update']
+
+ +
+ +
+
+
diff --git a/notebook/static/test.html b/notebook/static/test.html index d4e6b62..98023c2 100644 --- a/notebook/static/test.html +++ b/notebook/static/test.html @@ -13141,10 +13141,10 @@
-
In [6]:
+
In [7]:
-
import os;os.path.dirname('./test.html'.replace('./', './static/'))
+
import os;print(os.path.dirname('./test.html'.replace('./', './static/')))
 
@@ -13157,15 +13157,13 @@
-
Out[6]:
- - +
-
-
'./static'
+
+
./static
+
-
@@ -13204,6 +13202,54 @@
+
+
+
+
In [ ]:
+
+
+
%E9%9D%A2%E8%AF%95%E9%A2%9864.%E6%B1%821%2B2%2B%E2%80%A6%2Bn
+
+ +
+
+
+ +
+
+
+
In [9]:
+
+
+
url = '面试题64.求1+2+…+n.html'
+import urllib
+urllib.parse.quote(url)
+
+ +
+
+
+ +
+
+ + +
+ +
Out[9]:
+ + + + +
+
'%E9%9D%A2%E8%AF%95%E9%A2%9864.%E6%B1%821%2B2%2B%E2%80%A6%2Bn.html'
+
+ +
+ +
+
+
diff --git a/notebook/test.ipynb b/notebook/test.ipynb index c106985..0f85d18 100644 --- a/notebook/test.ipynb +++ b/notebook/test.ipynb @@ -108,10 +108,608 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function create_engine in module sqlalchemy.engine:\n", + "\n", + "create_engine(*args, **kwargs)\n", + " Create a new :class:`_engine.Engine` instance.\n", + " \n", + " The standard calling form is to send the URL as the\n", + " first positional argument, usually a string\n", + " that indicates database dialect and connection arguments::\n", + " \n", + " \n", + " engine = create_engine(\"postgresql://scott:tiger@localhost/test\")\n", + " \n", + " Additional keyword arguments may then follow it which\n", + " establish various options on the resulting :class:`_engine.Engine`\n", + " and its underlying :class:`.Dialect` and :class:`_pool.Pool`\n", + " constructs::\n", + " \n", + " engine = create_engine(\"mysql://scott:tiger@hostname/dbname\",\n", + " encoding='latin1', echo=True)\n", + " \n", + " The string form of the URL is\n", + " ``dialect[+driver]://user:password@host/dbname[?key=value..]``, where\n", + " ``dialect`` is a database name such as ``mysql``, ``oracle``,\n", + " ``postgresql``, etc., and ``driver`` the name of a DBAPI, such as\n", + " ``psycopg2``, ``pyodbc``, ``cx_oracle``, etc. Alternatively,\n", + " the URL can be an instance of :class:`~sqlalchemy.engine.url.URL`.\n", + " \n", + " ``**kwargs`` takes a wide variety of options which are routed\n", + " towards their appropriate components. Arguments may be specific to\n", + " the :class:`_engine.Engine`, the underlying :class:`.Dialect`,\n", + " as well as the\n", + " :class:`_pool.Pool`. Specific dialects also accept keyword arguments that\n", + " are unique to that dialect. Here, we describe the parameters\n", + " that are common to most :func:`_sa.create_engine()` usage.\n", + " \n", + " Once established, the newly resulting :class:`_engine.Engine` will\n", + " request a connection from the underlying :class:`_pool.Pool` once\n", + " :meth:`_engine.Engine.connect` is called, or a method which depends on it\n", + " such as :meth:`_engine.Engine.execute` is invoked. The\n", + " :class:`_pool.Pool` in turn\n", + " will establish the first actual DBAPI connection when this request\n", + " is received. The :func:`_sa.create_engine` call itself does **not**\n", + " establish any actual DBAPI connections directly.\n", + " \n", + " .. seealso::\n", + " \n", + " :doc:`/core/engines`\n", + " \n", + " :doc:`/dialects/index`\n", + " \n", + " :ref:`connections_toplevel`\n", + " \n", + " :param case_sensitive=True: if False, result column names\n", + " will match in a case-insensitive fashion, that is,\n", + " ``row['SomeColumn']``.\n", + " \n", + " :param connect_args: a dictionary of options which will be\n", + " passed directly to the DBAPI's ``connect()`` method as\n", + " additional keyword arguments. See the example\n", + " at :ref:`custom_dbapi_args`.\n", + " \n", + " :param convert_unicode=False: if set to True, causes\n", + " all :class:`.String` datatypes to act as though the\n", + " :paramref:`.String.convert_unicode` flag has been set to ``True``,\n", + " regardless of a setting of ``False`` on an individual :class:`.String`\n", + " type. This has the effect of causing all :class:`.String` -based\n", + " columns to accommodate Python Unicode objects directly as though the\n", + " datatype were the :class:`.Unicode` type.\n", + " \n", + " .. deprecated:: 1.3\n", + " \n", + " The :paramref:`_sa.create_engine.convert_unicode` parameter\n", + " is deprecated and will be removed in a future release.\n", + " All modern DBAPIs now support Python Unicode directly and this\n", + " parameter is unnecessary.\n", + " \n", + " :param creator: a callable which returns a DBAPI connection.\n", + " This creation function will be passed to the underlying\n", + " connection pool and will be used to create all new database\n", + " connections. Usage of this function causes connection\n", + " parameters specified in the URL argument to be bypassed.\n", + " \n", + " :param echo=False: if True, the Engine will log all statements\n", + " as well as a ``repr()`` of their parameter lists to the default log\n", + " handler, which defaults to ``sys.stdout`` for output. If set to the\n", + " string ``\"debug\"``, result rows will be printed to the standard output\n", + " as well. The ``echo`` attribute of ``Engine`` can be modified at any\n", + " time to turn logging on and off; direct control of logging is also\n", + " available using the standard Python ``logging`` module.\n", + " \n", + " .. seealso::\n", + " \n", + " :ref:`dbengine_logging` - further detail on how to configure\n", + " logging.\n", + " \n", + " :param echo_pool=False: if True, the connection pool will log\n", + " informational output such as when connections are invalidated\n", + " as well as when connections are recycled to the default log handler,\n", + " which defaults to ``sys.stdout`` for output. If set to the string\n", + " ``\"debug\"``, the logging will include pool checkouts and checkins.\n", + " Direct control of logging is also available using the standard Python\n", + " ``logging`` module.\n", + " \n", + " .. seealso::\n", + " \n", + " :ref:`dbengine_logging` - further detail on how to configure\n", + " logging.\n", + " \n", + " \n", + " :param empty_in_strategy: The SQL compilation strategy to use when\n", + " rendering an IN or NOT IN expression for :meth:`.ColumnOperators.in_`\n", + " where the right-hand side\n", + " is an empty set. This is a string value that may be one of\n", + " ``static``, ``dynamic``, or ``dynamic_warn``. The ``static``\n", + " strategy is the default, and an IN comparison to an empty set\n", + " will generate a simple false expression \"1 != 1\". The ``dynamic``\n", + " strategy behaves like that of SQLAlchemy 1.1 and earlier, emitting\n", + " a false expression of the form \"expr != expr\", which has the effect\n", + " of evaluting to NULL in the case of a null expression.\n", + " ``dynamic_warn`` is the same as ``dynamic``, however also emits a\n", + " warning when an empty set is encountered; this because the \"dynamic\"\n", + " comparison is typically poorly performing on most databases.\n", + " \n", + " .. versionadded:: 1.2 Added the ``empty_in_strategy`` setting and\n", + " additionally defaulted the behavior for empty-set IN comparisons\n", + " to a static boolean expression.\n", + " \n", + " :param encoding: Defaults to ``utf-8``. This is the string\n", + " encoding used by SQLAlchemy for string encode/decode\n", + " operations which occur within SQLAlchemy, **outside of\n", + " the DBAPIs own encoding facilities.**\n", + " \n", + " .. note:: The ``encoding`` parameter deals only with in-Python\n", + " encoding issues that were prevalent with many DBAPIs under Python\n", + " 2. Under Python 3 it is mostly unused. For DBAPIs that require\n", + " client encoding configurations, such as those of MySQL and Oracle,\n", + " please consult specific :ref:`dialect documentation\n", + " ` for details.\n", + " \n", + " All modern DBAPIs that work in Python 3 necessarily feature direct\n", + " support for Python unicode strings. Under Python 2, this was not\n", + " always the case. For those scenarios where the DBAPI is detected as\n", + " not supporting a Python ``unicode`` object under Python 2, this\n", + " encoding is used to determine the source/destination encoding. It is\n", + " **not used** for those cases where the DBAPI handles unicode directly.\n", + " \n", + " To properly configure a system to accommodate Python ``unicode``\n", + " objects, the DBAPI should be configured to handle unicode to the\n", + " greatest degree as is appropriate - see the notes on unicode pertaining\n", + " to the specific target database in use at :ref:`dialect_toplevel`.\n", + " \n", + " Areas where string encoding may need to be accommodated\n", + " outside of the DBAPI, nearly always under **Python 2 only**,\n", + " include zero or more of:\n", + " \n", + " * the values passed to bound parameters, corresponding to\n", + " the :class:`.Unicode` type or the :class:`.String` type\n", + " when ``convert_unicode`` is ``True``;\n", + " * the values returned in result set columns corresponding\n", + " to the :class:`.Unicode` type or the :class:`.String`\n", + " type when ``convert_unicode`` is ``True``;\n", + " * the string SQL statement passed to the DBAPI's\n", + " ``cursor.execute()`` method;\n", + " * the string names of the keys in the bound parameter\n", + " dictionary passed to the DBAPI's ``cursor.execute()``\n", + " as well as ``cursor.setinputsizes()`` methods;\n", + " * the string column names retrieved from the DBAPI's\n", + " ``cursor.description`` attribute.\n", + " \n", + " When using Python 3, the DBAPI is required to support all of the above\n", + " values as Python ``unicode`` objects, which in Python 3 are just known\n", + " as ``str``. In Python 2, the DBAPI does not specify unicode behavior\n", + " at all, so SQLAlchemy must make decisions for each of the above values\n", + " on a per-DBAPI basis - implementations are completely inconsistent in\n", + " their behavior.\n", + " \n", + " :param execution_options: Dictionary execution options which will\n", + " be applied to all connections. See\n", + " :meth:`~sqlalchemy.engine.Connection.execution_options`\n", + " \n", + " :param hide_parameters: Boolean, when set to True, SQL statement parameters\n", + " will not be displayed in INFO logging nor will they be formatted into\n", + " the string representation of :class:`.StatementError` objects.\n", + " \n", + " .. versionadded:: 1.3.8\n", + " \n", + " :param implicit_returning=True: When ``True``, a RETURNING-\n", + " compatible construct, if available, will be used to\n", + " fetch newly generated primary key values when a single row\n", + " INSERT statement is emitted with no existing returning()\n", + " clause. This applies to those backends which support RETURNING\n", + " or a compatible construct, including PostgreSQL, Firebird, Oracle,\n", + " Microsoft SQL Server. Set this to ``False`` to disable\n", + " the automatic usage of RETURNING.\n", + " \n", + " :param isolation_level: this string parameter is interpreted by various\n", + " dialects in order to affect the transaction isolation level of the\n", + " database connection. The parameter essentially accepts some subset of\n", + " these string arguments: ``\"SERIALIZABLE\"``, ``\"REPEATABLE_READ\"``,\n", + " ``\"READ_COMMITTED\"``, ``\"READ_UNCOMMITTED\"`` and ``\"AUTOCOMMIT\"``.\n", + " Behavior here varies per backend, and\n", + " individual dialects should be consulted directly.\n", + " \n", + " Note that the isolation level can also be set on a\n", + " per-:class:`_engine.Connection` basis as well, using the\n", + " :paramref:`.Connection.execution_options.isolation_level`\n", + " feature.\n", + " \n", + " .. seealso::\n", + " \n", + " :attr:`_engine.Connection.default_isolation_level`\n", + " - view default level\n", + " \n", + " :paramref:`.Connection.execution_options.isolation_level`\n", + " - set per :class:`_engine.Connection` isolation level\n", + " \n", + " :ref:`SQLite Transaction Isolation `\n", + " \n", + " :ref:`PostgreSQL Transaction Isolation `\n", + " \n", + " :ref:`MySQL Transaction Isolation `\n", + " \n", + " :ref:`session_transaction_isolation` - for the ORM\n", + " \n", + " :param json_deserializer: for dialects that support the\n", + " :class:`_types.JSON`\n", + " datatype, this is a Python callable that will convert a JSON string\n", + " to a Python object. By default, the Python ``json.loads`` function is\n", + " used.\n", + " \n", + " .. versionchanged:: 1.3.7 The SQLite dialect renamed this from\n", + " ``_json_deserializer``.\n", + " \n", + " :param json_serializer: for dialects that support the :class:`_types.JSON`\n", + " datatype, this is a Python callable that will render a given object\n", + " as JSON. By default, the Python ``json.dumps`` function is used.\n", + " \n", + " .. versionchanged:: 1.3.7 The SQLite dialect renamed this from\n", + " ``_json_serializer``.\n", + " \n", + " :param label_length=None: optional integer value which limits\n", + " the size of dynamically generated column labels to that many\n", + " characters. If less than 6, labels are generated as\n", + " \"_(counter)\". If ``None``, the value of\n", + " ``dialect.max_identifier_length``, which may be affected via the\n", + " :paramref:`_sa.create_engine.max_identifier_length` parameter,\n", + " is used instead. The value of\n", + " :paramref:`_sa.create_engine.label_length`\n", + " may not be larger than that of\n", + " :paramref:`_sa.create_engine.max_identfier_length`.\n", + " \n", + " .. seealso::\n", + " \n", + " :paramref:`_sa.create_engine.max_identifier_length`\n", + " \n", + " :param listeners: A list of one or more\n", + " :class:`~sqlalchemy.interfaces.PoolListener` objects which will\n", + " receive connection pool events.\n", + " \n", + " :param logging_name: String identifier which will be used within\n", + " the \"name\" field of logging records generated within the\n", + " \"sqlalchemy.engine\" logger. Defaults to a hexstring of the\n", + " object's id.\n", + " \n", + " :param max_identifier_length: integer; override the max_identifier_length\n", + " determined by the dialect. if ``None`` or zero, has no effect. This\n", + " is the database's configured maximum number of characters that may be\n", + " used in a SQL identifier such as a table name, column name, or label\n", + " name. All dialects determine this value automatically, however in the\n", + " case of a new database version for which this value has changed but\n", + " SQLAlchemy's dialect has not been adjusted, the value may be passed\n", + " here.\n", + " \n", + " .. versionadded:: 1.3.9\n", + " \n", + " .. seealso::\n", + " \n", + " :paramref:`_sa.create_engine.label_length`\n", + " \n", + " :param max_overflow=10: the number of connections to allow in\n", + " connection pool \"overflow\", that is connections that can be\n", + " opened above and beyond the pool_size setting, which defaults\n", + " to five. this is only used with :class:`~sqlalchemy.pool.QueuePool`.\n", + " \n", + " :param module=None: reference to a Python module object (the module\n", + " itself, not its string name). Specifies an alternate DBAPI module to\n", + " be used by the engine's dialect. Each sub-dialect references a\n", + " specific DBAPI which will be imported before first connect. This\n", + " parameter causes the import to be bypassed, and the given module to\n", + " be used instead. Can be used for testing of DBAPIs as well as to\n", + " inject \"mock\" DBAPI implementations into the :class:`_engine.Engine`.\n", + " \n", + " :param paramstyle=None: The `paramstyle `_\n", + " to use when rendering bound parameters. This style defaults to the\n", + " one recommended by the DBAPI itself, which is retrieved from the\n", + " ``.paramstyle`` attribute of the DBAPI. However, most DBAPIs accept\n", + " more than one paramstyle, and in particular it may be desirable\n", + " to change a \"named\" paramstyle into a \"positional\" one, or vice versa.\n", + " When this attribute is passed, it should be one of the values\n", + " ``\"qmark\"``, ``\"numeric\"``, ``\"named\"``, ``\"format\"`` or\n", + " ``\"pyformat\"``, and should correspond to a parameter style known\n", + " to be supported by the DBAPI in use.\n", + " \n", + " :param pool=None: an already-constructed instance of\n", + " :class:`~sqlalchemy.pool.Pool`, such as a\n", + " :class:`~sqlalchemy.pool.QueuePool` instance. If non-None, this\n", + " pool will be used directly as the underlying connection pool\n", + " for the engine, bypassing whatever connection parameters are\n", + " present in the URL argument. For information on constructing\n", + " connection pools manually, see :ref:`pooling_toplevel`.\n", + " \n", + " :param poolclass=None: a :class:`~sqlalchemy.pool.Pool`\n", + " subclass, which will be used to create a connection pool\n", + " instance using the connection parameters given in the URL. Note\n", + " this differs from ``pool`` in that you don't actually\n", + " instantiate the pool in this case, you just indicate what type\n", + " of pool to be used.\n", + " \n", + " :param pool_logging_name: String identifier which will be used within\n", + " the \"name\" field of logging records generated within the\n", + " \"sqlalchemy.pool\" logger. Defaults to a hexstring of the object's\n", + " id.\n", + " \n", + " :param pool_pre_ping: boolean, if True will enable the connection pool\n", + " \"pre-ping\" feature that tests connections for liveness upon\n", + " each checkout.\n", + " \n", + " .. versionadded:: 1.2\n", + " \n", + " .. seealso::\n", + " \n", + " :ref:`pool_disconnects_pessimistic`\n", + " \n", + " :param pool_size=5: the number of connections to keep open\n", + " inside the connection pool. This used with\n", + " :class:`~sqlalchemy.pool.QueuePool` as\n", + " well as :class:`~sqlalchemy.pool.SingletonThreadPool`. With\n", + " :class:`~sqlalchemy.pool.QueuePool`, a ``pool_size`` setting\n", + " of 0 indicates no limit; to disable pooling, set ``poolclass`` to\n", + " :class:`~sqlalchemy.pool.NullPool` instead.\n", + " \n", + " :param pool_recycle=-1: this setting causes the pool to recycle\n", + " connections after the given number of seconds has passed. It\n", + " defaults to -1, or no timeout. For example, setting to 3600\n", + " means connections will be recycled after one hour. Note that\n", + " MySQL in particular will disconnect automatically if no\n", + " activity is detected on a connection for eight hours (although\n", + " this is configurable with the MySQLDB connection itself and the\n", + " server configuration as well).\n", + " \n", + " .. seealso::\n", + " \n", + " :ref:`pool_setting_recycle`\n", + " \n", + " :param pool_reset_on_return='rollback': set the\n", + " :paramref:`_pool.Pool.reset_on_return` parameter of the underlying\n", + " :class:`_pool.Pool` object, which can be set to the values\n", + " ``\"rollback\"``, ``\"commit\"``, or ``None``.\n", + " \n", + " .. seealso::\n", + " \n", + " :paramref:`_pool.Pool.reset_on_return`\n", + " \n", + " :param pool_timeout=30: number of seconds to wait before giving\n", + " up on getting a connection from the pool. This is only used\n", + " with :class:`~sqlalchemy.pool.QueuePool`.\n", + " \n", + " :param pool_use_lifo=False: use LIFO (last-in-first-out) when retrieving\n", + " connections from :class:`.QueuePool` instead of FIFO\n", + " (first-in-first-out). Using LIFO, a server-side timeout scheme can\n", + " reduce the number of connections used during non- peak periods of\n", + " use. When planning for server-side timeouts, ensure that a recycle or\n", + " pre-ping strategy is in use to gracefully handle stale connections.\n", + " \n", + " .. versionadded:: 1.3\n", + " \n", + " .. seealso::\n", + " \n", + " :ref:`pool_use_lifo`\n", + " \n", + " :ref:`pool_disconnects`\n", + " \n", + " :param plugins: string list of plugin names to load. See\n", + " :class:`.CreateEnginePlugin` for background.\n", + " \n", + " .. versionadded:: 1.2.3\n", + " \n", + " :param strategy='plain': selects alternate engine implementations.\n", + " Currently available are:\n", + " \n", + " * the ``threadlocal`` strategy, which is described in\n", + " :ref:`threadlocal_strategy`;\n", + " * the ``mock`` strategy, which dispatches all statement\n", + " execution to a function passed as the argument ``executor``.\n", + " See `example in the FAQ\n", + " `_.\n", + " \n", + " :param executor=None: a function taking arguments\n", + " ``(sql, *multiparams, **params)``, to which the ``mock`` strategy will\n", + " dispatch all statement execution. Used only by ``strategy='mock'``.\n", + "\n" + ] + } + ], + "source": [ + "from sqlalchemy import create_engine\n", + "help(create_engine)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "14 % 10" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-2" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "-12 % -10" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "-123 // -10" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-1230" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "-123 * 10" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-1" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 * -1" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "res = '12'\n", + "res[:3]\n", + "1 // 2" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 0, 1]\n", + "0\n", + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n" + ] + }, + { + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5]" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nums = [0, 0, 1, 1, 2, 3, 4]\n", + "print(nums[:3])\n", + "for i in range(len(nums)):\n", + " print(i)\n", + " if i == 3:\n", + " nums.remove(i)\n", + " \n", + "[1, 2][:2]\n", + "[1, 2, 3, 4, 5, 6][:5]" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "datetime.datetime(2020, 6, 13, 12, 24, 55)" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from datetime import date\n", + "date(2020, 6, 22).isoformat()\n", + "from datetime import datetime\n", + "datetime(2020, 6, 13, 12, 24, 55)\n" + ] } ], "metadata": { diff --git a/notebook/utils.py b/notebook/utils.py new file mode 100644 index 0000000..09546ed --- /dev/null +++ b/notebook/utils.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# Author: wxnacy(wxnacy@gmail.com) +# Description: + +class ListNode(object): + def __init__(self, x): + self.val = x + self.next = None + +def array2listnode(arr: list): + '''数组转为链表''' + ln = ListNode(0) + l = ln + for i in arr: + l.next = ListNode(i) + l = l.next + return ln.next + +def listnode2array(ln: ListNode): + '''链表转为数组''' + arr = [] + while ln: + arr.append(ln.val) + ln = ln.next + return arr diff --git a/python/async_demo/test.py b/python/async_demo/test.py new file mode 100644 index 0000000..acf3533 --- /dev/null +++ b/python/async_demo/test.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# Author: wxnacy(wxnacy@gmail.com) +# Description: + +import aiohttp +import asyncio + +async def get(n): + print('begin') + await asyncio.sleep(1) + print('end') + # async with aiohttp.ClientSession() as client: + # print('begin') + # resp = await client.get(f'http://httpbin.org/delay/{n}') + # result = await resp.json() + # print + # print(result) + +# asyncio.run(get(1)) +import time +b = time.time() +loop = asyncio.get_event_loop() +tasks = [] +for i in range(10): + tasks.append(get(i)) +# tasks = [wget(host) for host in ['www.sina.com.cn', 'www.sohu.com', 'www.163.com']] +loop.run_until_complete(asyncio.wait(tasks)) +print(asyncio.current_task(loop)) +loop.close() +print(time.time() - b) diff --git a/python/fastapi_demo/async_decortor.py b/python/fastapi_demo/async_decortor.py new file mode 100644 index 0000000..437433d --- /dev/null +++ b/python/fastapi_demo/async_decortor.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# Author: wxnacy(wxnacy@gmail.com) +# Description: + +from functools import wraps +from functools import update_wrapper + +from inspect import isfunction + +CACHE = {} +import asyncio + +def cached(timeout=600, key_prefix=None): + """ + 缓存 + """ + def _wrapper(func): + @wraps(func) + async def _wrapped(*args, **kwargs): + cache_key = func.__name__ + + cache_data = CACHE.get(cache_key) + if cache_data: + return cache_data + res = await func(*args, **kwargs) + if timeout > 0: + CACHE[cache_key] = res + else: + CACHE[cache_key] = res + return res + + return _wrapped + return _wrapper + +from datetime import datetime + +@cached() +async def test(): + print(CACHE) + res = datetime.now().isoformat() + print(res) + return res + +asyncio.run(test()) +asyncio.run(test()) +asyncio.run(test()) diff --git a/python/fastapi_demo/depends.py b/python/fastapi_demo/depends.py new file mode 100644 index 0000000..3c08f39 --- /dev/null +++ b/python/fastapi_demo/depends.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# Author: wxnacy(wxnacy@gmail.com) +# Description: + +from fastapi import FastAPI +from typing import Optional +from fastapi import Body + +from fastapi import Depends + +app = FastAPI() + +async def common_parameters(q: Optional[str] = None, skip: int = Body(0, title='test'), limit: int = 100): + return {"q": q, "skip": skip, "limit": limit} + + +@app.get("/items/") +async def read_items(commons: dict = Depends(common_parameters)): + return commons + + +@app.get("/users/") +async def read_users(commons: dict = Depends(common_parameters)): + return commons diff --git a/python/fastapi_demo/first/depends.py b/python/fastapi_demo/first/depends.py new file mode 100644 index 0000000..e69de29 diff --git a/python/sqlalchemy_demo/select.py b/python/sqlalchemy_demo/select.py new file mode 100644 index 0000000..3e63bcc --- /dev/null +++ b/python/sqlalchemy_demo/select.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# Author: wxnacy(wxnacy@gmail.com) +# Description: + +from sqlalchemy import create_engine +from sqlalchemy import Column, Integer, String +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker + +SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:wxnacy@127.0.0.1:3306/study?charset=utf8mb4' +engine = create_engine(SQLALCHEMY_DATABASE_URI, echo=True) +Base = declarative_base() +Session = sessionmaker(bind=engine) +session = Session() + +class Book(Base): + __tablename__ = 'book' + id = Column(Integer, primary_key=True) + name = Column(String(132)) + +from sqlalchemy import select + +query = select([Book], Book.id ==1) + +res = session.execute(query) +print(query) +print(res) diff --git a/test/test b/test/test index 7e5894c..1f1f585 100644 --- a/test/test +++ b/test/test @@ -1,3 +1,16 @@ +执行用时: 56 ms , 在所有 Python3 提交中击败了 18.41% 的用户 +内存消耗: 13.8 MB , 在所有 Python3 提交中击败了 7.14% 的用户 +执行用时: 84 ms , 在所有 Python3 提交中击败了 78.10% 的用户 +内存消耗: 19.9 MB , 在所有 Python3 提交中击败了 100.00% +的用户 +执行用时: 96 ms , 在所有 Python3 提交中击败了 44.85% 的用户 +内存消耗: 23 MB , 在所有 Python3 提交中击败了 100.00% 的用户 +执行用时: 48 ms , 在所有 Python3 提交中击败了 76.34% 的用户 +内存消耗: 14.8 MB , 在所有 Python3 提交中击败了 8.16% 的用户 +执行用时: 44 ms , 在所有 Python3 提交中击败了 55.70% 的用户 +内存消耗: 13.7 MB , 在所有 Python3 提交中击败了 5.22% 的用户 +执行用时: 56 ms , 在所有 Python3 提交中击败了 84.47% 的用户 +内存消耗: 13.7 MB , 在所有 Python3 提交中击败了 6.45% 的用户 chrome --headless --disable-gpu https://wxnacy.com chrome --headless --disable-gpu --remote-debugging-port=9222 https://wxnacy.com chrome --headless --disable-gpu --screenshot https://wxnacy.com