From 0a35df894ea872164e5e21aa90cd1d58cf87157e Mon Sep 17 00:00:00 2001 From: Priya Date: Sun, 11 Dec 2022 17:15:28 -0600 Subject: [PATCH 1/5] Completed python practice assignment --- python_practice_12_09.py | 209 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 python_practice_12_09.py diff --git a/python_practice_12_09.py b/python_practice_12_09.py new file mode 100644 index 0000000..00ca5d3 --- /dev/null +++ b/python_practice_12_09.py @@ -0,0 +1,209 @@ +# Biggie Size - Given a list, write a function that changes all positive numbers in the list to "big". +# Example: make_it_big([-1, 3, 5, -5]) returns that same list, #changed to [-1, "big", "big", -5]. +def change_positive(): + user_input_list = [int(item) for item in input("Enter the list items for Biggie Size (positive or negative integers) : ").split()] + print(user_input_list) + for count, item in enumerate(user_input_list): + if item > 0: + user_input_list[count] = "big" + return user_input_list + +# Count Positives - Given a list of numbers, +# create a function to replace last value with number of positive values. +# Example, count_positives([-1,1,1,1]) changes list #to [-1,1,1,3] and returns it. +# (Note that zero is not considered to be a positive number). +def count_positive(): + count = 0 + user_input_list = [int(item) for item in input("Enter the list items for count positives (positive or negative integers) : ").split()] + for item in user_input_list: + if item > 0: + count += 1 + user_input_list.pop() + user_input_list.append(count) + return user_input_list + +# SumTotal - Create a function that takes a list as an argument and returns the +# sum of all the values in the list. +# For example sum_total([1,2,3,4]) should return 10 +def sum_total(): + user_input_list = [int(item) for item in input("Enter the list items for sumtotal (positive or negative integers) : ").split()] + sum = 0 + for item in user_input_list: + sum += item + return sum + + +# Average - Create a function that takes a list as an argument and returns the average +# of all the values in the list. For example multiples([1,2,3,4]) should return #2.5 +def average(): + user_input_list = [int(item) for item in input("Enter the list items to find average (positive or negative integers) : ").split()] + sum1 = 0 + counter = 0 + for item in user_input_list: + sum1 += item + counter += 1 + avg = sum1 / counter + return avg + +# Length - Create a function that takes a list as an argument and returns the length of the list. +# For example length([1,2,3,4]) should return 4 +def length(): + user_input_list = [int(item) for item in input("Enter the list items to find it's length (positive or negative integers) : ").split()] + count = 0 + for item in user_input_list: + count += 1 + return count + + +# Minimum - Create a function that takes a list as an argument and returns the minimum value in the list. +# If the passed list is empty, have the function return false. +# #For example minimum([1,2,3,4]) should return 1; minimum([-1,-2,-3]) should return -3. +def minimum(): + user_input_list = [int(item) for item in input("Enter the list items to find minimum value (positive or negative integers) : ").split()] + if not user_input_list: + return False + temp = user_input_list[0] + for item in user_input_list: + if item < temp: + temp = item + return temp + + +# Maximum - Create a function that takes a list as an argument and returns the maximum value in the list. +# If the passed list is empty, have the function return false. +# #For example maximum([1,2,3,4]) should return 4; maximum([-1,-2,-3]) should return -1. +def maximum(): + user_input_list = [int(item) for item in input("Enter the list items to find maximum value (positive or negative integers) : ").split()] + if not user_input_list: + return False + temp = user_input_list[0] + for item in user_input_list: + if item > temp: + temp = item + return temp + + +# Ultimateaalyze - Create a function that takes a list as an argument and returns a +# dictionary that has the sumTotal, average, minimum, maximum ad length of the list. +def ultimate_dict(): + user_input_list = [int(item) for item in input("Enter the list items for Ultimateaalyze dict(positive or negative integers) : ").split()] + result = {} + result["sumtotal"] = sum(user_input_list) + result["average"] = sum(user_input_list)/len(user_input_list) + result["minimum"] = min(user_input_list) + result["maximum"] = max(user_input_list) + result["length"] = len(user_input_list) + return result + + +# ReverseList - Create a function that takes a list as a argument and return a list in a reversed order. +# Do this without creating a empty temporary list. For example #reverse([1,2,3,4]) should return [4,3,2,1]. +# This challenge is known to appear during basic technical interviews. +def list_reverse(): + user_input_list = [int(item) for item in input("Enter the list items to reverse(positive or negative integers) : ").split()] + return user_input_list[::-1] + + +# Ispalindrome- Given a string, write a python function to check if it is palindrome or not. +# A string is said to be palindrome if the reverse of the string is the same as string. +# For example, “radar” is a palindrome, but “radix” is not a palindrome. +def is_palindrome(): + input_sentence=input("Enter string to check for palindrome: ") + input_sentence = input_sentence.lower() + input_sentence = input_sentence.split() + input_sentence = ",".join(input_sentence) + input_sentence = input_sentence.replace(",", "") + # print(word1) + if input_sentence == input_sentence[::-1]: + return True + return False + +# Fizzbuzz- Create a function that will print numbers from 1 to 100, with certain exceptions: +# If the number is a multiple of 3, print “Fizz” instead of the number. +# If the number is a multiple of 5, print “Buzz” instead of the number. +# If the number is a multiple of 3 and 5, print “FizzBuzz” instead of the number. +def fizzbuzz(): + #print("print FizzBuzz for numbers in range of 1 to 100") + start = int(input(" Enter the starting range for FizzBuzz: ")) + end = int(input(" Enter the ending range for FizzBuzz: ")) + fb = ["FizzBuzz" if (num % 3 == 0 and num % 5 == 0) else "Fizz" if (num % 3 == 0) else "Buzz" if ( + num % 5 == 0) else num for num in range(start, end+1)] + return fb + + +# Fibonacci- The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, +# such that each number is the sum of the two preceding ones, #starting from 0 and 1. That is, +# F(0) = 0, F(1) = 1 +# F(n) = F(n - 1) + F(n - 2), for n > 1. +# Create a function that accepts any number and will create a sequence based on the fibonacci sequence. +def fibonacci_recur(n): + if (n >= 0): + if n <= 1: + return n + else: + return (fibonacci_recur(n - 1) + fibonacci_recur(n - 2)) + + +# get input from user + +print('''Enter choice from below: + 1.Change postitve numbers to \"big\" + 2.Count positive values and replace last value to count + 3.Sum of all list items + 4.Average of all list items + 5.Length of thr list + 6.Minimum value in the list + 7.Maximum value in the list + 8.Dictionary with sum, average, max, min and length of input list + 9.Reverse the given list + 10.Check for palindrome + 11.FizzBuzz + 12.Fibonacci sequence + 13.Exit''') +user_choice = 100 # initializing with random int value +while int(user_choice) != 13: + user_choice = input("Please enter your choice: ") + if user_choice.isspace(): + print(" Invalid user choice") + user_choice = 0 + elif user_choice not in ['1','2','3','4','5','6','7','8','9','10','11','12','13']: + print("Invalid user choice ") + user_choice=0 + elif int(user_choice) == 1: + # function call + print("change positive numbers to \"big\" in list:", change_positive()) + elif int(user_choice) == 2: + # function call + print("count positive values in the list and replace last value with positive item count :", count_positive()) + elif int(user_choice) == 3: + # function call + print("sum of all list items in :", sum_total()) + elif int(user_choice) == 4: + # function call + print("average of list items in :", average()) + elif int(user_choice) == 5: + # function call + print("length of list items:", length()) + elif int(user_choice) == 6: + # function call + print("minimum value in the list : ", minimum()) + elif int(user_choice) == 7: + print("maximum value in the list: ", maximum()) + elif int(user_choice) == 8: + # function call + print("Dict with aggregate functions of list: ", ultimate_dict()) + elif int(user_choice) == 9: + # function call + print("reverse of the list :", list_reverse()) + elif int(user_choice) == 10: + print("palindrome : ", is_palindrome()) + elif int(user_choice) == 11: + # function call + print("Callin FuzzBuzz: ", fizzbuzz()) + elif int(user_choice) == 12: + # function call + n = int(input("Enter input value for fibonacci sequence: ")) + print("Fibonacci sequence : ", fibonacci_recur(n)) + elif int(user_choice) == 13: + print("Exiting") + exit \ No newline at end of file From 83b058ac42a1d1bfb8d8ee15055a6f7a6e5f3ac2 Mon Sep 17 00:00:00 2001 From: Priya Date: Sun, 11 Dec 2022 22:46:03 -0600 Subject: [PATCH 2/5] modified assignmet --- python_practice_12_09.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/python_practice_12_09.py b/python_practice_12_09.py index 00ca5d3..79ae6c9 100644 --- a/python_practice_12_09.py +++ b/python_practice_12_09.py @@ -137,11 +137,10 @@ def fizzbuzz(): # F(n) = F(n - 1) + F(n - 2), for n > 1. # Create a function that accepts any number and will create a sequence based on the fibonacci sequence. def fibonacci_recur(n): - if (n >= 0): - if n <= 1: - return n - else: - return (fibonacci_recur(n - 1) + fibonacci_recur(n - 2)) + if n<2: + return n + else: + return (fibonacci_recur(n - 1) + fibonacci_recur(n - 2)) # get input from user From 359fd277b3f84e55b84e33d82c1589ddf7c306b4 Mon Sep 17 00:00:00 2001 From: Priya Date: Wed, 14 Dec 2022 12:01:31 -0600 Subject: [PATCH 3/5] completed python advance topics assignment --- gen_iterator_lambda.py | 238 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 gen_iterator_lambda.py diff --git a/gen_iterator_lambda.py b/gen_iterator_lambda.py new file mode 100644 index 0000000..ec9794c --- /dev/null +++ b/gen_iterator_lambda.py @@ -0,0 +1,238 @@ +from functools import reduce +from datetime import timezone, datetime + +#Create a generator, primes_gen that generates prime numbers +#starting from 2. + +def primes_gen(): + for i in range(2,100): + for j in range(2,i): + if i%j==0: + break + else: + yield i + +gen = primes_gen() +for _ in range(10): + print(next(gen), end=' ') + + +################## unique _letter generator +#def unique_let_gen(): + + +def unique_letters(input_word): + #unique = set() + #unique=list() + unique=[] + for char in input_word: + if char not in unique: + yield char + #unique.add(char) + unique.append(char) + +for letter in unique_letters('hello'): + print(letter, end=' ') + + + +'''Use list comprehension to create a list containing a solution for the +famous FizzBuzz problem. For integers 1 to 100, inclusively, the value +should be: +➢ 'Fizz' if divisible by 3 +➢ 'Buzz' if divisible by 5 +➢ 'FizzBuzz' if divisible by both 3 and 5 +➢ The integer itself if not divisible by both 3 and 5''' +fb = ["FizzBuzz" if (num % 3 == 0 and num % 5 == 0) else "Fizz" if (num % 3 == 0) else "Buzz" if ( + num % 5 == 0) else num for num in range(1, 100+1)] + +print(fb) + +#Generators Exercise +#Sort the list by each language's version in ascending order.''' +prog_lang = [('Python', 3.8), +('Java', 13), +('JavaScript', 2019), +('Scala', 2.13)] + +#1.Lambda function to print asc order on version +prog_lang.sort(key=lambda a: a[1]) +print(prog_lang) + +#2.Sort the list by the length of the name of each language in descendingorder. + +prog_lang.sort(reverse=True, key=lambda item: len(item[0])) +print(prog_lang) + +#3.Filter the list so that it only contains languages with 'a' in it. + +output_list=list(filter(lambda item: "a" in item[0],prog_lang)) +print(output_list) + +#4.Filter the list so that it only contains languages whose version is in integer form. + +output_list=list(filter(lambda item: type(item[1])==int ,prog_lang)) +print(output_list) + +#5.Transform the list so that it contains the tuples in the form, +#("language in all lower case", length of the language string) + +output_list=list(map(lambda item: (item[0].lower(),len(item[0])),prog_lang)) +print(output_list) + +#6.Generate a tuple in the form, +#("All languages separated by commas", +#"All versions separated by commas") + +input_string = tuple(map(lambda item : (item[0]),prog_lang)) +input_num_string = tuple(map(lambda item : (str(item[1])),prog_lang)) +print((' '.join(input_string), ' '.join(input_num_string))) + +print(reduce(lambda x,y:(f'{x[0]},{y[0]}',f'{x[1]},{y[1]}') , prog_lang)) + +'''Using a closure, create a function, multiples_of(n) which we can use to +create generators that generate multiples of n less than a given +number.''' + +def multiples_of(n): + def multiplier(x): + for i in range(x): + multiple=(i+1)*n + if multiple<30: + yield multiple + return multiplier + +m3 = multiples_of(3) +m3_under30 = m3(30) +m7_under30 = multiples_of(7)(30) + +print(type(m3_under30)) +# output: + +print(*m3_under30) +# output: 3 6 9 12 15 18 21 24 27 + +print(*m7_under30) +# output: 7 14 21 28 + +#1.make_upper – make every letter of a string returned from the decorated +#function uppercase. +def make_upper(func): + def upper_case(): + str = func() + return str.upper() + return upper_case + + +@make_upper +def hello_world(): + return 'hello young good day!!' + + +print(hello_world()) # output: HELLO YOUNG, GOOD DAY!! + +#2.print_func_name – print the name of the decorated function before +#executing the function. + +def print_func_name(func): + def inner(): + print(func.__qualname__ +" is running...") + print(func.__name__ + " is running...") + func() + return inner + + +@print_func_name +def my_func(): + print('Python is fun!!') + +my_func() # output: my_func is running... + # Python is fun + +#3.give_name(name) – concatenate the given name at the end of a string +#returned from the decorated function. + +def give_name(name): + def inner(func): + def wrapper(): + return func()+" "+name + return wrapper + return inner + + +@give_name('Theresa') +def greeting(): + return 'Hello' + +print(greeting()) # output: Hello Theresa + +#4.print_input_type – print a data type of the input argument before +#executing the decorated function. +def print_input_type(func): + def inner(n): + print("The input data type is ", type(n)) + return func(n) + return inner + +@print_input_type +def square(n): + return n ** 2 + +print(square(3.5)) # output: The input data type is + #12.25 + +#5.check_return_type(return_type) – check if the return type of the +#decorated function is return_type and print the result before executing +#the function. + +def check_return_type(rtyp): + #print(rtyp) + def inner(func): + def wrapper(n): + #ret_type=type(func(n)) + #print(ret_type) + if (type(func(n))==rtyp): + print("The return type is",type(func(n),),func(n)) + else: + print("---------Error!--------- The return type is NOT ",func(n)) + return wrapper + return inner + +@check_return_type(str) +def square(n): + return n ** 2 + +print(square(6)) # output: =========Error!! +#=========The return type is NOT +#36 + +@check_return_type(float) +def square(n): + return n ** 2 + +print(square(2.9)) # output: The return type is Date: Tue, 20 Dec 2022 16:22:03 -0600 Subject: [PATCH 4/5] regex exercise completed --- regex_excercises.ipynb | 1105 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1105 insertions(+) create mode 100644 regex_excercises.ipynb diff --git a/regex_excercises.ipynb b/regex_excercises.ipynb new file mode 100644 index 0000000..90b7434 --- /dev/null +++ b/regex_excercises.ipynb @@ -0,0 +1,1105 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "mtZQDWxxos3J" + }, + "source": [ + "# 30 REGULAR EXPRESSION EXERCISES!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "6jEYHJH3os3Q" + }, + "source": [ + "Regex, you never know when they might come in handy. It's one of the \"good programmer\"'s fundamental yet a few people actually masters them.\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "ghj1l7sQos3R", + "trusted": true + }, + "outputs": [], + "source": [ + "import re" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_tO-OHUBos3T" + }, + "source": [ + "1) Write a Python program to check that a string contains only a certain set of characters (in this case a-z, A-Z and 0-9)." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "cXaMTykzos3V", + "outputId": "a73c9558-3ac4-44e9-ad0f-685a8f627983", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], + "source": [ + "# Solution\n", + "def is_allowed_specific_char(string):\n", + " # Define a regex pattern\n", + " pattern = r'^[\\w]+$'\n", + " # Use the pattern to search for ....\n", + " return bool(re.search(pattern, string))\n", + " \n", + "print(is_allowed_specific_char(\"ABCDEFabcdef123450\")) # True\n", + "print(is_allowed_specific_char(\"*&%@#!}{\")) # False" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2oae-B8tos3W" + }, + "source": [ + "2) Write a Python program that matches a string that has an a followed by zero or more b's" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "1LHEOOMkos3X", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " pattern=r'(ab*)'\n", + " return \"Found a match\" if re.search(pattern,text) else \"Not matched\"\n", + "\n", + "print(text_match(\"ac\")) # Found a match!\n", + "print(text_match(\"abc\")) # Found a match!\n", + "print(text_match(\"abbc\")) # Found a match!\n", + "print(text_match(\"bbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "AQRTCmJZos3Z" + }, + "source": [ + "3) Write a Python program that matches a string that has an a followed by one or more b's" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "H1X2NPQYos3a", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " pattern=r'(ab+)'\n", + " return \"Found a match\" if re.search(pattern,text) else \"Not matched\"\n", + "\n", + "print(text_match(\"ab\")) # Found a match!\n", + "print(text_match(\"abc\")) # Found a match!\n", + "print(text_match(\"ac\")) # Not matched\n", + "print(text_match(\"bbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "E902uTcRos3a" + }, + "source": [ + "4) Write a Python program that matches a string that has an a followed by zero or one 'b'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "xeva0fRNos3b", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " pattern=r'(ab?)'\n", + " return \"Found a match\" if re.search(pattern,text) else \"Not matched\"\n", + " \n", + "print(text_match(\"ab\")) # Found a match!\n", + "print(text_match(\"abc\")) # Found a match!\n", + "print(text_match(\"abbc\")) # Found a match!\n", + "print(text_match(\"aabbc\")) # Found a match!\n", + "print(text_match(\"ac\")) # Found a match!\n", + "print(text_match(\"bbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "whnPaW2kos3c" + }, + "source": [ + "5) Write a Python program that matches a string that has an a followed by three 'b'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "0c_7S3h_os3d", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " pattern=r'(abbb)'\n", + " return \"Found a match\" if re.search(pattern,text) else \"Not matched\"\n", + "\n", + "print(text_match(\"abbb\")) # Found a match!\n", + "print(text_match(\"aabbbbbc\")) # Found a match!\n", + "print(text_match(\"aabbc\")) # Not matched\n", + "print(text_match(\"ac\")) # Not matched\n", + "print(text_match(\"bbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "V4AsjJiCos3e" + }, + "source": [ + "6) Write a Python program that matches a string that has an a followed by two to three 'b'." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "VjA5CXi1os3e", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " pattern=r'(a[b]{2,3})'\n", + " return \"Found a match\" if re.search(pattern,text) else \"Not matched\"\n", + "\n", + "print(text_match(\"ab\")) # Not matched\n", + "print(text_match(\"aabbbbbc\")) # Found a match!\n", + "print(text_match(\"aabbc\")) # Found a match!\n", + "print(text_match(\"ac\")) # Not matched\n", + "print(text_match(\"bbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kX7sLRavos3f" + }, + "source": [ + "7) Write a Python program to find sequences of lowercase letters joined with a underscore." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "rbxk35n7os3g", + "outputId": "3ddca986-1bd6-45f1-902c-eee85e8853e8", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " pattern=r'(^[a-z][^A-Z]*_[a-z][^A-Z]*)'\n", + " return \"Found a match\" if re.search(pattern,text) else \"Not matched\"\n", + "\n", + "print(text_match(\"aab_cbbbc\")) # Found a match!\n", + "print(text_match(\"aab_Abbbc\")) # Not matched\n", + "print(text_match(\"Aaab_abbbc\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "H4sat-Rfos3g" + }, + "source": [ + "8) Write a Python program to find the sequences of one upper case letter followed by lower case letters." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "oeUiVHGVos3h", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " pattern=r'([a-z]*[A-Z][a-z]*\\w)'\n", + " return \"Found a match\" if re.search(pattern,text) else \"Not matched\"\n", + "\n", + "\n", + "print(text_match(\"aab_cbbbc\")) # Not matched\n", + "print(text_match(\"aab_Abbbc\")) # Found a match!\n", + "print(text_match(\"Aaab_abbbc\")) # Found a match!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "RgNBl7aEos3h" + }, + "source": [ + "9) Write a Python program that matches a string that has an 'a' followed by anything, ending in 'b'." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "YbCsos7Jos3i", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " pattern=r'([a-z]*b$)'\n", + " return \"Found a match\" if re.search(pattern,text) else \"Not matched\"\n", + "\n", + "\n", + "print(text_match(\"aabbbbd\")) # Not matched\n", + "print(text_match(\"aabAbbbc\")) # Not matched\n", + "print(text_match(\"accddbbjjjb\")) # Found a match!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0oHZnx0Gos3i" + }, + "source": [ + "10) Write a Python program that matches a word at the beginning of a string." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "1tlZiGMaos3j", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " return \"Found a match\" if re.search(r'^[^\\s]',text) else \"Not matched\"\n", + "\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog.\")) # Found a match!\n", + "print(text_match(\" The quick brown fox jumps over the lazy dog.\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "mG0jspZFos3j" + }, + "source": [ + "11) Write a Python program that matches a word at the end of string, with optional punctuation." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "cmhnhbZnos3j", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " return \"Found a match\" if re.search(r'([a-z]\\.$)',text) else \"Not matched\"\n", + "\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog.\")) # Found a match!\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog. \")) # Not matched\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog \")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DBgbyYHXos3k" + }, + "source": [ + "12) Write a Python program that matches a word containing 'z'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "WxuMRyCbos3k", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " return \"Found a match\" if re.search(r'([a-z]*z[a-z]*)',text) else \"Not matched\"\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog.\")) # Found a match!\n", + "print(text_match(\"Python Exercises.\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "V_9_nk8Kos3l" + }, + "source": [ + "13) Write a Python program that matches a word containing 'z', not at the start or end of the word." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "VEhCCh7yos3l", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " return \"Found a match\" if re.search(r'([a-y]+z[a-y]+)',text) else \"Not matched\"\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog.\")) # Found a match!\n", + "print(text_match(\"Python Exercises.\")) # Not matched" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "L0lV07OCos3m" + }, + "source": [ + "14) Write a Python program to match a string that contains only upper and lowercase letters, numbers, and underscores." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "E9NcoWDhos3m", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def text_match(text):\n", + " return \"Not matched\" if re.search(r'(^(\\w)+\\s)',text) else \"Found a match\"\n", + "\n", + "print(text_match(\"The quick brown fox jumps over the lazy dog.\")) # Not matched\n", + "print(text_match(\"Python_Exercises_1\")) # Found a match!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "EvKJ8WOoos3n" + }, + "source": [ + "15) Write a Python program where a string will start with a specific number. " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "nWp5QysTos3n", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], + "source": [ + "# Solution\n", + "def match_num(string):\n", + " return bool(re.search(r'^(5)',string))\n", + "print(match_num('5-2345861')) # True\n", + "print(match_num('6-2345861')) # False" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "r_I1cbvios3t" + }, + "source": [ + "16) Write a Python program to remove leading zeros from an IP address" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "cRLX4hc3os3u", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def rewrite_ip(ip):\n", + " # your code here\n", + " ipre = re.sub(r'\\.[0]*','.', ip)\n", + " return ipre\n", + "\n", + "ip = \"216.08.094.196\"\n", + "string = rewrite_ip(ip)\n", + "print(string) # 216.8.94.196" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZCn9r3o2os3u" + }, + "source": [ + "17) Write a Python program to check for a number at the end of a string." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Q5t9U6n8os3u", + "trusted": true + }, + "outputs": [], + "source": [ + "# Solution\n", + "def end_num(string):\n", + " return bool(re.search(r'*[0-9]$',string))\n", + "print(end_num('abcdef')) # False\n", + "print(end_num('abcdef6')) # True" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0tM4eW8Wos3v" + }, + "source": [ + "18) Write a Python program to search the numbers (0-9) of length between 1 to 3 in a given string. " + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number pf length 1 to 3\n", + "1\n", + "12\n", + "13\n", + "345\n" + ] + } + ], + "source": [ + "def print_digits(string):\n", + " ipre = re.findall(r'[0-9]{1,3}',string)\n", + " print (\"Number pf length 1 to 3\")\n", + " for item in ipre:\n", + " print(item)\n", + "\n", + "string = \"Exercises number 1, 12, 13, and 345 are important\"\n", + "print_digits(string)\n", + "# Number of length 1 to 3\n", + "# 1\n", + "# 12\n", + "# 13\n", + "# 345" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "43nNb7d_os3v" + }, + "source": [ + "19) Write a Python program to search some literals strings in a string. \n", + "Sample text : 'The quick brown fox jumps over the lazy dog.'\n", + "Searched words : 'fox', 'dog', 'horse'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "KIVHxWN9os3w", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "searching for fox in \"The quick brown fox jumps over the lazy dog.\"\n", + "Matched\n", + "searching for dog in \"The quick brown fox jumps over the lazy dog.\"\n", + "Matched\n", + "searching for horse in \"The quick brown fox jumps over the lazy dog.\"\n", + "not Matched\n" + ] + } + ], + "source": [ + "# Solution\n", + "def print_match(patterns, text):\n", + " for pattern in patterns:\n", + " print(f\"searching for {pattern} in \\\"{text}\\\"\")\n", + " print(\"Matched\" if re.search(pattern,text) else \"not Matched\")\n", + "\n", + "patterns = [ 'fox', 'dog', 'horse' ]\n", + "text = 'The quick brown fox jumps over the lazy dog.'\n", + "print_match(patterns, text)\n", + "# Searching for \"fox\" in \"The quick brown fox jumps over the lazy dog.\" ->\n", + "# Matched!\n", + "# Searching for \"dog\" in \"The quick brown fox jumps over the lazy dog.\" ->\n", + "# Matched!\n", + "# Searching for \"horse\" in \"The quick brown fox jumps over the lazy dog.\" ->\n", + "# Not Matched!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XjdROmMhos3w" + }, + "source": [ + "20) Write a Python program to search a literals string in a string and also find the location within the original string where the pattern occurs\n", + "\n", + "Sample text : 'The quick brown fox jumps over the lazy dog.'\n", + "Searched words : 'fox'" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "vWViImYios3w", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found \"fox\" in \"The quick brown fox jumps over the lazy dog.\" from 16 to 19\n" + ] + } + ], + "source": [ + "# Solution\n", + "def print_match_location(pattern, text):\n", + " match=re.search(pattern,text)\n", + " print(f\"Found \\\"{pattern}\\\" in \\\"{text}\\\" from {match.start()} to {match.end()}\")\n", + "\n", + "pattern = 'fox'\n", + "text = 'The quick brown fox jumps over the lazy dog.'\n", + "print_match_location(pattern, text)\n", + "# Found \"fox\" in \"The quick brown fox jumps over the lazy dog.\" from 16 to 19" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "lLRotk-Oos3x" + }, + "source": [ + "21) Write a Python program to find the substrings within a string.\n", + "\n", + "Sample text :\n", + "\n", + "'Python exercises, PHP exercises, C# exercises'\n", + "\n", + "Pattern :\n", + "\n", + "'exercises'\n", + "\n", + "Note: There are three instances of exercises in the input string." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "XU8613rTos3x", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found:\"exercises\"\n", + "Found:\"exercises\"\n", + "Found:\"exercises\"\n" + ] + } + ], + "source": [ + "# Solution\n", + "def find_all_matches(pattern, text):\n", + " match=re.findall(pattern,text)\n", + " for item in match:\n", + " print(f\"Found:\\\"{item}\\\"\")\n", + "\n", + "text = 'Python exercises, PHP exercises, C# exercises'\n", + "pattern = 'exercises'\n", + "find_all_matches(pattern, text)\n", + "# Found \"exercises\"\n", + "# Found \"exercises\"\n", + "# Found \"exercises\"" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "uvAY6v7Oos3x" + }, + "source": [ + "22) Write a Python program to find the occurrence and position of the substrings within a string." + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "id": "UFg6rXJnos3y", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found:\"exercises\" at 7:16\n", + "Found:\"exercises\" at 22:31\n", + "Found:\"exercises\" at 36:45\n" + ] + } + ], + "source": [ + "# Solution\n", + "def find_all_matches_location(pattern, text):\n", + " match=re.finditer(pattern,text)\n", + " for item in match:\n", + " print(f\"Found:\\\"{item.group()}\\\" at {item.start()}:{item.end()}\")\n", + "\n", + "\n", + "\n", + "text = 'Python exercises, PHP exercises, C# exercises'\n", + "pattern = 'exercises'\n", + "find_all_matches_location(pattern, text)\n", + "# Found \"exercises\" at 7:16\n", + "# Found \"exercises\" at 22:31\n", + "# Found \"exercises\" at 36:45" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Sb3zKxE-os3y" + }, + "source": [ + "23) Write a Python program to replace whitespaces with an underscore and vice versa." + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "id": "nUxR5Xvjos3z", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python_Exercises\n", + "Python Exercises\n" + ] + } + ], + "source": [ + "text = 'Python Exercises'\n", + "text=re.sub(r'\\s',\"_\",text)\n", + "\n", + "print(text) # Python_Exercises\n", + "text=re.sub(\"_\",\" \",text)\n", + "\n", + "print(text) # Python Exercises" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "grqoW-pgos3z" + }, + "source": [ + "24) Write a Python program to extract year, month and date from a an url. " + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": { + "id": "K2-pacqmos3z", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['2016', '09', '02']\n" + ] + } + ], + "source": [ + "# Solution\n", + "def extract_date(url):\n", + " return re.findall(r'[0-9]{1,4}',url)\n", + " \n", + "url1= \"https://www.washingtonpost.com/news/football-insider/wp/2016/09/02/odell-beckhams-fame-rests-on-one-stupid-little-ball-josh-norman-tells-author/\"\n", + "print(extract_date(url1)) # [('2016', '09', '02')]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gyD5AZW7os3z" + }, + "source": [ + "25) Write a Python program to convert a date of yyyy-mm-dd format to dd-mm-yyyy format." + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": { + "id": "bo-jpYqZos30", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original date in YYY-MM-DD Format: 2026-01-02\n", + "New date in DD-MM-YYYY Format: 02-01-2026\n" + ] + } + ], + "source": [ + "# Solution\n", + "def change_date_format(dt):\n", + " #pattern=r'(\\d){4}-(\\d){2}-(\\d){2}'\n", + " pattern=r'(\\d*)-(\\d*)-(\\d*)'\n", + " match=re.search(pattern,dt)\n", + " return(f\"{match.group(3)}-{match.group(2)}-{match.group(1)}\")\n", + " \n", + "\n", + "\n", + "dt1 = \"2026-01-02\"\n", + "print(\"Original date in YYY-MM-DD Format: \",dt1) # Original date in YYY-MM-DD Format: 2026-01-02\n", + "print(\"New date in DD-MM-YYYY Format: \",change_date_format(dt1)) # New date in DD-MM-YYYY Format: 02-01-2026" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IQ2SNL-gos30" + }, + "source": [ + "26) Write a Python program to match if any words from a list of words starting with letter 'P'." + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": { + "id": "2hP4Twe0os31", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Java JavaScript\n", + "Python PHP\n", + "['Python', 'PHP']\n", + "c c++\n" + ] + } + ], + "source": [ + "# Sample strings.\n", + "def print_words_starting_with_P(words):\n", + " pattern=r'(\\b[Pp]\\w*)'\n", + " for word in words:\n", + " #print(word)\n", + " match=re.findall(pattern,word)\n", + " if match:\n", + " print(match)\n", + "\n", + "words = [\"Java JavaScript\",\"Python PHP\", \"c c++\"]\n", + "print_words_starting_with_P(words) # ('Python', 'PHP')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "MEUMKMn0os31" + }, + "source": [ + "27) Write a Python program to separate and print the numbers of a given string." + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": { + "id": "xG8c9PtUos32", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "20\n", + "30\n" + ] + } + ], + "source": [ + "# Solution\n", + "def print_all_numbers(text):\n", + " pattern=r'(\\d+)'\n", + " match=re.findall(pattern,text)\n", + " for item in match:\n", + " print(item)\n", + " \n", + "\n", + "# Sample string.\n", + "text = \"Ten 10, Twenty 20, Thirty 30\"\n", + "print_all_numbers(text)\n", + "# 10\n", + "# 20\n", + "# 30" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "krdKu3Mvos32" + }, + "source": [ + "28) Write a Python program to find all words starting with 'a' or 'e' in a given string." + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": { + "id": "3hsR5278os32", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['example', 'eates', 'an', 'ayList', 'apacity', 'elements', 'elements', 'are', 'en', 'added', 'ayList', 'and', 'ayList', 'ed', 'accordingly']\n" + ] + } + ], + "source": [ + "# Solution\n", + "def get_all_words_containing_a_or_e(text):\n", + " #pattern=r'(\\sa\\w*|\\se\\w*)'\n", + " pattern=r'(a\\w+|e\\w+)'\n", + " return (re.findall(pattern,text))\n", + "\n", + "\n", + "# Input.\n", + "text = \"The following example creates an ArrayList with a capacity of 50 elements. Four elements are then added to the ArrayList and the ArrayList is trimmed accordingly.\"\n", + "print(get_all_words_containing_a_or_e(text))\n", + "# ['example', 'eates', 'an', 'ayList', 'apacity', 'elements', 'elements', 'are', 'en', 'added', 'ayList', 'and', 'ayList', 'ed', 'accordingly']" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "CxfIZ5o9os33" + }, + "source": [ + "29) Write a Python program to separate and print the numbers and their position of a given string." + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": { + "id": "XIuiRvmAos33", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "50\n", + "index position:62\n" + ] + } + ], + "source": [ + "# Solution\n", + "def print_all_numbers_and_their_position(text):\n", + " pattern=r'(\\d+)'\n", + " match=re.finditer(pattern,text)\n", + " for item in match:\n", + " print(item.group())\n", + " print(f\"index position:{item.start()}\")\n", + " \n", + "\n", + "# Input.\n", + "text = \"The following example creates an ArrayList with a capacity of 50 elements. Four elements are then added to the ArrayList and the ArrayList is trimmed accordingly.\"\n", + "print_all_numbers_and_their_position(text)\n", + "# 50\n", + "# Index position: 62" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JguO0fUjos34" + }, + "source": [ + "30) Write a Python program to abbreviate 'Road' as 'Rd.' in a given string." + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": { + "id": "VJE1Xm2Bos34", + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "21 Ramkrishna Rd.\n" + ] + } + ], + "source": [ + "# Solution\n", + "def abbreviate_road(street):\n", + " match=re.sub(\"Road\",\"Rd.\",street)\n", + " return match\n", + "\n", + "street = '21 Ramkrishna Road'\n", + "\n", + "print(abbreviate_road(street)) # 21 Ramkrishna Rd.\n" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "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.11.0" + }, + "vscode": { + "interpreter": { + "hash": "fc8b46890068e2a6de32ffa038f77616ac3974d41ce3c2c3a4261acff02db9ff" + } + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From f8cb1b41e645fe1144908b0101a05796e8c1fc1e Mon Sep 17 00:00:00 2001 From: Priya Date: Thu, 12 Jan 2023 22:33:43 -0600 Subject: [PATCH 5/5] Starship API workouts --- starship_api.ipynb | 1024 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1024 insertions(+) create mode 100644 starship_api.ipynb diff --git a/starship_api.ipynb b/starship_api.ipynb new file mode 100644 index 0000000..42b145c --- /dev/null +++ b/starship_api.ipynb @@ -0,0 +1,1024 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "import json\n", + "from pprint import pp" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "https://swapi.dev/api/starships/?page=2\n", + "https://swapi.dev/api/starships/?page=3\n", + "https://swapi.dev/api/starships/?page=4\n", + "None\n", + "[{'name': 'CR90 corvette',\n", + " 'model': 'CR90 corvette',\n", + " 'manufacturer': 'Corellian Engineering Corporation',\n", + " 'cost_in_credits': '3500000',\n", + " 'length': '150',\n", + " 'max_atmosphering_speed': '950',\n", + " 'crew': '30-165',\n", + " 'passengers': '600',\n", + " 'cargo_capacity': '3000000',\n", + " 'consumables': '1 year',\n", + " 'hyperdrive_rating': '2.0',\n", + " 'MGLT': '60',\n", + " 'starship_class': 'corvette',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/1/',\n", + " 'https://swapi.dev/api/films/3/',\n", + " 'https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-10T14:20:33.369000Z',\n", + " 'edited': '2014-12-20T21:23:49.867000Z',\n", + " 'url': 'https://swapi.dev/api/starships/2/'},\n", + " {'name': 'Star Destroyer',\n", + " 'model': 'Imperial I-class Star Destroyer',\n", + " 'manufacturer': 'Kuat Drive Yards',\n", + " 'cost_in_credits': '150000000',\n", + " 'length': '1,600',\n", + " 'max_atmosphering_speed': '975',\n", + " 'crew': '47,060',\n", + " 'passengers': 'n/a',\n", + " 'cargo_capacity': '36000000',\n", + " 'consumables': '2 years',\n", + " 'hyperdrive_rating': '2.0',\n", + " 'MGLT': '60',\n", + " 'starship_class': 'Star Destroyer',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/1/',\n", + " 'https://swapi.dev/api/films/2/',\n", + " 'https://swapi.dev/api/films/3/'],\n", + " 'created': '2014-12-10T15:08:19.848000Z',\n", + " 'edited': '2014-12-20T21:23:49.870000Z',\n", + " 'url': 'https://swapi.dev/api/starships/3/'},\n", + " {'name': 'Sentinel-class landing craft',\n", + " 'model': 'Sentinel-class landing craft',\n", + " 'manufacturer': 'Sienar Fleet Systems, Cyngus Spaceworks',\n", + " 'cost_in_credits': '240000',\n", + " 'length': '38',\n", + " 'max_atmosphering_speed': '1000',\n", + " 'crew': '5',\n", + " 'passengers': '75',\n", + " 'cargo_capacity': '180000',\n", + " 'consumables': '1 month',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': '70',\n", + " 'starship_class': 'landing craft',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/1/'],\n", + " 'created': '2014-12-10T15:48:00.586000Z',\n", + " 'edited': '2014-12-20T21:23:49.873000Z',\n", + " 'url': 'https://swapi.dev/api/starships/5/'},\n", + " {'name': 'Death Star',\n", + " 'model': 'DS-1 Orbital Battle Station',\n", + " 'manufacturer': 'Imperial Department of Military Research, Sienar Fleet '\n", + " 'Systems',\n", + " 'cost_in_credits': '1000000000000',\n", + " 'length': '120000',\n", + " 'max_atmosphering_speed': 'n/a',\n", + " 'crew': '342,953',\n", + " 'passengers': '843,342',\n", + " 'cargo_capacity': '1000000000000',\n", + " 'consumables': '3 years',\n", + " 'hyperdrive_rating': '4.0',\n", + " 'MGLT': '10',\n", + " 'starship_class': 'Deep Space Mobile Battlestation',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/1/'],\n", + " 'created': '2014-12-10T16:36:50.509000Z',\n", + " 'edited': '2014-12-20T21:26:24.783000Z',\n", + " 'url': 'https://swapi.dev/api/starships/9/'},\n", + " {'name': 'Millennium Falcon',\n", + " 'model': 'YT-1300 light freighter',\n", + " 'manufacturer': 'Corellian Engineering Corporation',\n", + " 'cost_in_credits': '100000',\n", + " 'length': '34.37',\n", + " 'max_atmosphering_speed': '1050',\n", + " 'crew': '4',\n", + " 'passengers': '6',\n", + " 'cargo_capacity': '100000',\n", + " 'consumables': '2 months',\n", + " 'hyperdrive_rating': '0.5',\n", + " 'MGLT': '75',\n", + " 'starship_class': 'Light freighter',\n", + " 'pilots': ['https://swapi.dev/api/people/13/',\n", + " 'https://swapi.dev/api/people/14/',\n", + " 'https://swapi.dev/api/people/25/',\n", + " 'https://swapi.dev/api/people/31/'],\n", + " 'films': ['https://swapi.dev/api/films/1/',\n", + " 'https://swapi.dev/api/films/2/',\n", + " 'https://swapi.dev/api/films/3/'],\n", + " 'created': '2014-12-10T16:59:45.094000Z',\n", + " 'edited': '2014-12-20T21:23:49.880000Z',\n", + " 'url': 'https://swapi.dev/api/starships/10/'},\n", + " {'name': 'Y-wing',\n", + " 'model': 'BTL Y-wing',\n", + " 'manufacturer': 'Koensayr Manufacturing',\n", + " 'cost_in_credits': '134999',\n", + " 'length': '14',\n", + " 'max_atmosphering_speed': '1000km',\n", + " 'crew': '2',\n", + " 'passengers': '0',\n", + " 'cargo_capacity': '110',\n", + " 'consumables': '1 week',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': '80',\n", + " 'starship_class': 'assault starfighter',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/1/',\n", + " 'https://swapi.dev/api/films/2/',\n", + " 'https://swapi.dev/api/films/3/'],\n", + " 'created': '2014-12-12T11:00:39.817000Z',\n", + " 'edited': '2014-12-20T21:23:49.883000Z',\n", + " 'url': 'https://swapi.dev/api/starships/11/'},\n", + " {'name': 'X-wing',\n", + " 'model': 'T-65 X-wing',\n", + " 'manufacturer': 'Incom Corporation',\n", + " 'cost_in_credits': '149999',\n", + " 'length': '12.5',\n", + " 'max_atmosphering_speed': '1050',\n", + " 'crew': '1',\n", + " 'passengers': '0',\n", + " 'cargo_capacity': '110',\n", + " 'consumables': '1 week',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': '100',\n", + " 'starship_class': 'Starfighter',\n", + " 'pilots': ['https://swapi.dev/api/people/1/',\n", + " 'https://swapi.dev/api/people/9/',\n", + " 'https://swapi.dev/api/people/18/',\n", + " 'https://swapi.dev/api/people/19/'],\n", + " 'films': ['https://swapi.dev/api/films/1/',\n", + " 'https://swapi.dev/api/films/2/',\n", + " 'https://swapi.dev/api/films/3/'],\n", + " 'created': '2014-12-12T11:19:05.340000Z',\n", + " 'edited': '2014-12-20T21:23:49.886000Z',\n", + " 'url': 'https://swapi.dev/api/starships/12/'},\n", + " {'name': 'TIE Advanced x1',\n", + " 'model': 'Twin Ion Engine Advanced x1',\n", + " 'manufacturer': 'Sienar Fleet Systems',\n", + " 'cost_in_credits': 'unknown',\n", + " 'length': '9.2',\n", + " 'max_atmosphering_speed': '1200',\n", + " 'crew': '1',\n", + " 'passengers': '0',\n", + " 'cargo_capacity': '150',\n", + " 'consumables': '5 days',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': '105',\n", + " 'starship_class': 'Starfighter',\n", + " 'pilots': ['https://swapi.dev/api/people/4/'],\n", + " 'films': ['https://swapi.dev/api/films/1/'],\n", + " 'created': '2014-12-12T11:21:32.991000Z',\n", + " 'edited': '2014-12-20T21:23:49.889000Z',\n", + " 'url': 'https://swapi.dev/api/starships/13/'},\n", + " {'name': 'Executor',\n", + " 'model': 'Executor-class star dreadnought',\n", + " 'manufacturer': 'Kuat Drive Yards, Fondor Shipyards',\n", + " 'cost_in_credits': '1143350000',\n", + " 'length': '19000',\n", + " 'max_atmosphering_speed': 'n/a',\n", + " 'crew': '279,144',\n", + " 'passengers': '38000',\n", + " 'cargo_capacity': '250000000',\n", + " 'consumables': '6 years',\n", + " 'hyperdrive_rating': '2.0',\n", + " 'MGLT': '40',\n", + " 'starship_class': 'Star dreadnought',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/2/', 'https://swapi.dev/api/films/3/'],\n", + " 'created': '2014-12-15T12:31:42.547000Z',\n", + " 'edited': '2014-12-20T21:23:49.893000Z',\n", + " 'url': 'https://swapi.dev/api/starships/15/'},\n", + " {'name': 'Rebel transport',\n", + " 'model': 'GR-75 medium transport',\n", + " 'manufacturer': 'Gallofree Yards, Inc.',\n", + " 'cost_in_credits': 'unknown',\n", + " 'length': '90',\n", + " 'max_atmosphering_speed': '650',\n", + " 'crew': '6',\n", + " 'passengers': '90',\n", + " 'cargo_capacity': '19000000',\n", + " 'consumables': '6 months',\n", + " 'hyperdrive_rating': '4.0',\n", + " 'MGLT': '20',\n", + " 'starship_class': 'Medium transport',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/2/', 'https://swapi.dev/api/films/3/'],\n", + " 'created': '2014-12-15T12:34:52.264000Z',\n", + " 'edited': '2014-12-20T21:23:49.895000Z',\n", + " 'url': 'https://swapi.dev/api/starships/17/'},\n", + " {'name': 'Slave 1',\n", + " 'model': 'Firespray-31-class patrol and attack',\n", + " 'manufacturer': 'Kuat Systems Engineering',\n", + " 'cost_in_credits': 'unknown',\n", + " 'length': '21.5',\n", + " 'max_atmosphering_speed': '1000',\n", + " 'crew': '1',\n", + " 'passengers': '6',\n", + " 'cargo_capacity': '70000',\n", + " 'consumables': '1 month',\n", + " 'hyperdrive_rating': '3.0',\n", + " 'MGLT': '70',\n", + " 'starship_class': 'Patrol craft',\n", + " 'pilots': ['https://swapi.dev/api/people/22/'],\n", + " 'films': ['https://swapi.dev/api/films/2/', 'https://swapi.dev/api/films/5/'],\n", + " 'created': '2014-12-15T13:00:56.332000Z',\n", + " 'edited': '2014-12-20T21:23:49.897000Z',\n", + " 'url': 'https://swapi.dev/api/starships/21/'},\n", + " {'name': 'Imperial shuttle',\n", + " 'model': 'Lambda-class T-4a shuttle',\n", + " 'manufacturer': 'Sienar Fleet Systems',\n", + " 'cost_in_credits': '240000',\n", + " 'length': '20',\n", + " 'max_atmosphering_speed': '850',\n", + " 'crew': '6',\n", + " 'passengers': '20',\n", + " 'cargo_capacity': '80000',\n", + " 'consumables': '2 months',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': '50',\n", + " 'starship_class': 'Armed government transport',\n", + " 'pilots': ['https://swapi.dev/api/people/1/',\n", + " 'https://swapi.dev/api/people/13/',\n", + " 'https://swapi.dev/api/people/14/'],\n", + " 'films': ['https://swapi.dev/api/films/2/', 'https://swapi.dev/api/films/3/'],\n", + " 'created': '2014-12-15T13:04:47.235000Z',\n", + " 'edited': '2014-12-20T21:23:49.900000Z',\n", + " 'url': 'https://swapi.dev/api/starships/22/'},\n", + " {'name': 'EF76 Nebulon-B escort frigate',\n", + " 'model': 'EF76 Nebulon-B escort frigate',\n", + " 'manufacturer': 'Kuat Drive Yards',\n", + " 'cost_in_credits': '8500000',\n", + " 'length': '300',\n", + " 'max_atmosphering_speed': '800',\n", + " 'crew': '854',\n", + " 'passengers': '75',\n", + " 'cargo_capacity': '6000000',\n", + " 'consumables': '2 years',\n", + " 'hyperdrive_rating': '2.0',\n", + " 'MGLT': '40',\n", + " 'starship_class': 'Escort ship',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/2/', 'https://swapi.dev/api/films/3/'],\n", + " 'created': '2014-12-15T13:06:30.813000Z',\n", + " 'edited': '2014-12-20T21:23:49.902000Z',\n", + " 'url': 'https://swapi.dev/api/starships/23/'},\n", + " {'name': 'Calamari Cruiser',\n", + " 'model': 'MC80 Liberty type Star Cruiser',\n", + " 'manufacturer': 'Mon Calamari shipyards',\n", + " 'cost_in_credits': '104000000',\n", + " 'length': '1200',\n", + " 'max_atmosphering_speed': 'n/a',\n", + " 'crew': '5400',\n", + " 'passengers': '1200',\n", + " 'cargo_capacity': 'unknown',\n", + " 'consumables': '2 years',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': '60',\n", + " 'starship_class': 'Star Cruiser',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/3/'],\n", + " 'created': '2014-12-18T10:54:57.804000Z',\n", + " 'edited': '2014-12-20T21:23:49.904000Z',\n", + " 'url': 'https://swapi.dev/api/starships/27/'},\n", + " {'name': 'A-wing',\n", + " 'model': 'RZ-1 A-wing Interceptor',\n", + " 'manufacturer': 'Alliance Underground Engineering, Incom Corporation',\n", + " 'cost_in_credits': '175000',\n", + " 'length': '9.6',\n", + " 'max_atmosphering_speed': '1300',\n", + " 'crew': '1',\n", + " 'passengers': '0',\n", + " 'cargo_capacity': '40',\n", + " 'consumables': '1 week',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': '120',\n", + " 'starship_class': 'Starfighter',\n", + " 'pilots': ['https://swapi.dev/api/people/29/'],\n", + " 'films': ['https://swapi.dev/api/films/3/'],\n", + " 'created': '2014-12-18T11:16:34.542000Z',\n", + " 'edited': '2014-12-20T21:23:49.907000Z',\n", + " 'url': 'https://swapi.dev/api/starships/28/'},\n", + " {'name': 'B-wing',\n", + " 'model': 'A/SF-01 B-wing starfighter',\n", + " 'manufacturer': 'Slayn & Korpil',\n", + " 'cost_in_credits': '220000',\n", + " 'length': '16.9',\n", + " 'max_atmosphering_speed': '950',\n", + " 'crew': '1',\n", + " 'passengers': '0',\n", + " 'cargo_capacity': '45',\n", + " 'consumables': '1 week',\n", + " 'hyperdrive_rating': '2.0',\n", + " 'MGLT': '91',\n", + " 'starship_class': 'Assault Starfighter',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/3/'],\n", + " 'created': '2014-12-18T11:18:04.763000Z',\n", + " 'edited': '2014-12-20T21:23:49.909000Z',\n", + " 'url': 'https://swapi.dev/api/starships/29/'},\n", + " {'name': 'Republic Cruiser',\n", + " 'model': 'Consular-class cruiser',\n", + " 'manufacturer': 'Corellian Engineering Corporation',\n", + " 'cost_in_credits': 'unknown',\n", + " 'length': '115',\n", + " 'max_atmosphering_speed': '900',\n", + " 'crew': '9',\n", + " 'passengers': '16',\n", + " 'cargo_capacity': 'unknown',\n", + " 'consumables': 'unknown',\n", + " 'hyperdrive_rating': '2.0',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'Space cruiser',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/4/'],\n", + " 'created': '2014-12-19T17:01:31.488000Z',\n", + " 'edited': '2014-12-20T21:23:49.912000Z',\n", + " 'url': 'https://swapi.dev/api/starships/31/'},\n", + " {'name': 'Droid control ship',\n", + " 'model': 'Lucrehulk-class Droid Control Ship',\n", + " 'manufacturer': 'Hoersch-Kessel Drive, Inc.',\n", + " 'cost_in_credits': 'unknown',\n", + " 'length': '3170',\n", + " 'max_atmosphering_speed': 'n/a',\n", + " 'crew': '175',\n", + " 'passengers': '139000',\n", + " 'cargo_capacity': '4000000000',\n", + " 'consumables': '500 days',\n", + " 'hyperdrive_rating': '2.0',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'Droid control ship',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/4/',\n", + " 'https://swapi.dev/api/films/5/',\n", + " 'https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-19T17:04:06.323000Z',\n", + " 'edited': '2014-12-20T21:23:49.915000Z',\n", + " 'url': 'https://swapi.dev/api/starships/32/'},\n", + " {'name': 'Naboo fighter',\n", + " 'model': 'N-1 starfighter',\n", + " 'manufacturer': 'Theed Palace Space Vessel Engineering Corps',\n", + " 'cost_in_credits': '200000',\n", + " 'length': '11',\n", + " 'max_atmosphering_speed': '1100',\n", + " 'crew': '1',\n", + " 'passengers': '0',\n", + " 'cargo_capacity': '65',\n", + " 'consumables': '7 days',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'Starfighter',\n", + " 'pilots': ['https://swapi.dev/api/people/11/',\n", + " 'https://swapi.dev/api/people/35/',\n", + " 'https://swapi.dev/api/people/60/'],\n", + " 'films': ['https://swapi.dev/api/films/4/', 'https://swapi.dev/api/films/5/'],\n", + " 'created': '2014-12-19T17:39:17.582000Z',\n", + " 'edited': '2014-12-20T21:23:49.917000Z',\n", + " 'url': 'https://swapi.dev/api/starships/39/'},\n", + " {'name': 'Naboo Royal Starship',\n", + " 'model': 'J-type 327 Nubian royal starship',\n", + " 'manufacturer': 'Theed Palace Space Vessel Engineering Corps, Nubia Star '\n", + " 'Drives',\n", + " 'cost_in_credits': 'unknown',\n", + " 'length': '76',\n", + " 'max_atmosphering_speed': '920',\n", + " 'crew': '8',\n", + " 'passengers': 'unknown',\n", + " 'cargo_capacity': 'unknown',\n", + " 'consumables': 'unknown',\n", + " 'hyperdrive_rating': '1.8',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'yacht',\n", + " 'pilots': ['https://swapi.dev/api/people/39/'],\n", + " 'films': ['https://swapi.dev/api/films/4/'],\n", + " 'created': '2014-12-19T17:45:03.506000Z',\n", + " 'edited': '2014-12-20T21:23:49.919000Z',\n", + " 'url': 'https://swapi.dev/api/starships/40/'},\n", + " {'name': 'Scimitar',\n", + " 'model': 'Star Courier',\n", + " 'manufacturer': 'Republic Sienar Systems',\n", + " 'cost_in_credits': '55000000',\n", + " 'length': '26.5',\n", + " 'max_atmosphering_speed': '1180',\n", + " 'crew': '1',\n", + " 'passengers': '6',\n", + " 'cargo_capacity': '2500000',\n", + " 'consumables': '30 days',\n", + " 'hyperdrive_rating': '1.5',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'Space Transport',\n", + " 'pilots': ['https://swapi.dev/api/people/44/'],\n", + " 'films': ['https://swapi.dev/api/films/4/'],\n", + " 'created': '2014-12-20T09:39:56.116000Z',\n", + " 'edited': '2014-12-20T21:23:49.922000Z',\n", + " 'url': 'https://swapi.dev/api/starships/41/'},\n", + " {'name': 'J-type diplomatic barge',\n", + " 'model': 'J-type diplomatic barge',\n", + " 'manufacturer': 'Theed Palace Space Vessel Engineering Corps, Nubia Star '\n", + " 'Drives',\n", + " 'cost_in_credits': '2000000',\n", + " 'length': '39',\n", + " 'max_atmosphering_speed': '2000',\n", + " 'crew': '5',\n", + " 'passengers': '10',\n", + " 'cargo_capacity': 'unknown',\n", + " 'consumables': '1 year',\n", + " 'hyperdrive_rating': '0.7',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'Diplomatic barge',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/5/'],\n", + " 'created': '2014-12-20T11:05:51.237000Z',\n", + " 'edited': '2014-12-20T21:23:49.925000Z',\n", + " 'url': 'https://swapi.dev/api/starships/43/'},\n", + " {'name': 'AA-9 Coruscant freighter',\n", + " 'model': 'Botajef AA-9 Freighter-Liner',\n", + " 'manufacturer': 'Botajef Shipyards',\n", + " 'cost_in_credits': 'unknown',\n", + " 'length': '390',\n", + " 'max_atmosphering_speed': 'unknown',\n", + " 'crew': 'unknown',\n", + " 'passengers': '30000',\n", + " 'cargo_capacity': 'unknown',\n", + " 'consumables': 'unknown',\n", + " 'hyperdrive_rating': 'unknown',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'freighter',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/5/'],\n", + " 'created': '2014-12-20T17:24:23.509000Z',\n", + " 'edited': '2014-12-20T21:23:49.928000Z',\n", + " 'url': 'https://swapi.dev/api/starships/47/'},\n", + " {'name': 'Jedi starfighter',\n", + " 'model': 'Delta-7 Aethersprite-class interceptor',\n", + " 'manufacturer': 'Kuat Systems Engineering',\n", + " 'cost_in_credits': '180000',\n", + " 'length': '8',\n", + " 'max_atmosphering_speed': '1150',\n", + " 'crew': '1',\n", + " 'passengers': '0',\n", + " 'cargo_capacity': '60',\n", + " 'consumables': '7 days',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'Starfighter',\n", + " 'pilots': ['https://swapi.dev/api/people/10/',\n", + " 'https://swapi.dev/api/people/58/'],\n", + " 'films': ['https://swapi.dev/api/films/5/', 'https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-20T17:35:23.906000Z',\n", + " 'edited': '2014-12-20T21:23:49.930000Z',\n", + " 'url': 'https://swapi.dev/api/starships/48/'},\n", + " {'name': 'H-type Nubian yacht',\n", + " 'model': 'H-type Nubian yacht',\n", + " 'manufacturer': 'Theed Palace Space Vessel Engineering Corps',\n", + " 'cost_in_credits': 'unknown',\n", + " 'length': '47.9',\n", + " 'max_atmosphering_speed': '8000',\n", + " 'crew': '4',\n", + " 'passengers': 'unknown',\n", + " 'cargo_capacity': 'unknown',\n", + " 'consumables': 'unknown',\n", + " 'hyperdrive_rating': '0.9',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'yacht',\n", + " 'pilots': ['https://swapi.dev/api/people/35/'],\n", + " 'films': ['https://swapi.dev/api/films/5/'],\n", + " 'created': '2014-12-20T17:46:46.847000Z',\n", + " 'edited': '2014-12-20T21:23:49.932000Z',\n", + " 'url': 'https://swapi.dev/api/starships/49/'},\n", + " {'name': 'Republic Assault ship',\n", + " 'model': 'Acclamator I-class assault ship',\n", + " 'manufacturer': 'Rothana Heavy Engineering',\n", + " 'cost_in_credits': 'unknown',\n", + " 'length': '752',\n", + " 'max_atmosphering_speed': 'unknown',\n", + " 'crew': '700',\n", + " 'passengers': '16000',\n", + " 'cargo_capacity': '11250000',\n", + " 'consumables': '2 years',\n", + " 'hyperdrive_rating': '0.6',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'assault ship',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/5/'],\n", + " 'created': '2014-12-20T18:08:42.926000Z',\n", + " 'edited': '2014-12-20T21:23:49.935000Z',\n", + " 'url': 'https://swapi.dev/api/starships/52/'},\n", + " {'name': 'Solar Sailer',\n", + " 'model': 'Punworcca 116-class interstellar sloop',\n", + " 'manufacturer': 'Huppla Pasa Tisc Shipwrights Collective',\n", + " 'cost_in_credits': '35700',\n", + " 'length': '15.2',\n", + " 'max_atmosphering_speed': '1600',\n", + " 'crew': '3',\n", + " 'passengers': '11',\n", + " 'cargo_capacity': '240',\n", + " 'consumables': '7 days',\n", + " 'hyperdrive_rating': '1.5',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'yacht',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/5/'],\n", + " 'created': '2014-12-20T18:37:56.969000Z',\n", + " 'edited': '2014-12-20T21:23:49.937000Z',\n", + " 'url': 'https://swapi.dev/api/starships/58/'},\n", + " {'name': 'Trade Federation cruiser',\n", + " 'model': 'Providence-class carrier/destroyer',\n", + " 'manufacturer': 'Rendili StarDrive, Free Dac Volunteers Engineering corps.',\n", + " 'cost_in_credits': '125000000',\n", + " 'length': '1088',\n", + " 'max_atmosphering_speed': '1050',\n", + " 'crew': '600',\n", + " 'passengers': '48247',\n", + " 'cargo_capacity': '50000000',\n", + " 'consumables': '4 years',\n", + " 'hyperdrive_rating': '1.5',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'capital ship',\n", + " 'pilots': ['https://swapi.dev/api/people/10/',\n", + " 'https://swapi.dev/api/people/11/'],\n", + " 'films': ['https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-20T19:40:21.902000Z',\n", + " 'edited': '2014-12-20T21:23:49.941000Z',\n", + " 'url': 'https://swapi.dev/api/starships/59/'},\n", + " {'name': 'Theta-class T-2c shuttle',\n", + " 'model': 'Theta-class T-2c shuttle',\n", + " 'manufacturer': 'Cygnus Spaceworks',\n", + " 'cost_in_credits': '1000000',\n", + " 'length': '18.5',\n", + " 'max_atmosphering_speed': '2000',\n", + " 'crew': '5',\n", + " 'passengers': '16',\n", + " 'cargo_capacity': '50000',\n", + " 'consumables': '56 days',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'transport',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-20T19:48:40.409000Z',\n", + " 'edited': '2014-12-20T21:23:49.944000Z',\n", + " 'url': 'https://swapi.dev/api/starships/61/'},\n", + " {'name': 'Republic attack cruiser',\n", + " 'model': 'Senator-class Star Destroyer',\n", + " 'manufacturer': 'Kuat Drive Yards, Allanteen Six shipyards',\n", + " 'cost_in_credits': '59000000',\n", + " 'length': '1137',\n", + " 'max_atmosphering_speed': '975',\n", + " 'crew': '7400',\n", + " 'passengers': '2000',\n", + " 'cargo_capacity': '20000000',\n", + " 'consumables': '2 years',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'star destroyer',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-20T19:52:56.232000Z',\n", + " 'edited': '2014-12-20T21:23:49.946000Z',\n", + " 'url': 'https://swapi.dev/api/starships/63/'},\n", + " {'name': 'Naboo star skiff',\n", + " 'model': 'J-type star skiff',\n", + " 'manufacturer': 'Theed Palace Space Vessel Engineering Corps/Nubia Star '\n", + " 'Drives, Incorporated',\n", + " 'cost_in_credits': 'unknown',\n", + " 'length': '29.2',\n", + " 'max_atmosphering_speed': '1050',\n", + " 'crew': '3',\n", + " 'passengers': '3',\n", + " 'cargo_capacity': 'unknown',\n", + " 'consumables': 'unknown',\n", + " 'hyperdrive_rating': '0.5',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'yacht',\n", + " 'pilots': ['https://swapi.dev/api/people/10/',\n", + " 'https://swapi.dev/api/people/35/'],\n", + " 'films': ['https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-20T19:55:15.396000Z',\n", + " 'edited': '2014-12-20T21:23:49.948000Z',\n", + " 'url': 'https://swapi.dev/api/starships/64/'},\n", + " {'name': 'Jedi Interceptor',\n", + " 'model': 'Eta-2 Actis-class light interceptor',\n", + " 'manufacturer': 'Kuat Systems Engineering',\n", + " 'cost_in_credits': '320000',\n", + " 'length': '5.47',\n", + " 'max_atmosphering_speed': '1500',\n", + " 'crew': '1',\n", + " 'passengers': '0',\n", + " 'cargo_capacity': '60',\n", + " 'consumables': '2 days',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'starfighter',\n", + " 'pilots': ['https://swapi.dev/api/people/10/',\n", + " 'https://swapi.dev/api/people/11/'],\n", + " 'films': ['https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-20T19:56:57.468000Z',\n", + " 'edited': '2014-12-20T21:23:49.951000Z',\n", + " 'url': 'https://swapi.dev/api/starships/65/'},\n", + " {'name': 'arc-170',\n", + " 'model': 'Aggressive Reconnaissance-170 starfighte',\n", + " 'manufacturer': 'Incom Corporation, Subpro Corporation',\n", + " 'cost_in_credits': '155000',\n", + " 'length': '14.5',\n", + " 'max_atmosphering_speed': '1000',\n", + " 'crew': '3',\n", + " 'passengers': '0',\n", + " 'cargo_capacity': '110',\n", + " 'consumables': '5 days',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': '100',\n", + " 'starship_class': 'starfighter',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-20T20:03:48.603000Z',\n", + " 'edited': '2014-12-20T21:23:49.953000Z',\n", + " 'url': 'https://swapi.dev/api/starships/66/'},\n", + " {'name': 'Banking clan frigte',\n", + " 'model': 'Munificent-class star frigate',\n", + " 'manufacturer': 'Hoersch-Kessel Drive, Inc, Gwori Revolutionary Industries',\n", + " 'cost_in_credits': '57000000',\n", + " 'length': '825',\n", + " 'max_atmosphering_speed': 'unknown',\n", + " 'crew': '200',\n", + " 'passengers': 'unknown',\n", + " 'cargo_capacity': '40000000',\n", + " 'consumables': '2 years',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'cruiser',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-20T20:07:11.538000Z',\n", + " 'edited': '2014-12-20T21:23:49.956000Z',\n", + " 'url': 'https://swapi.dev/api/starships/68/'},\n", + " {'name': 'Belbullab-22 starfighter',\n", + " 'model': 'Belbullab-22 starfighter',\n", + " 'manufacturer': 'Feethan Ottraw Scalable Assemblies',\n", + " 'cost_in_credits': '168000',\n", + " 'length': '6.71',\n", + " 'max_atmosphering_speed': '1100',\n", + " 'crew': '1',\n", + " 'passengers': '0',\n", + " 'cargo_capacity': '140',\n", + " 'consumables': '7 days',\n", + " 'hyperdrive_rating': '6',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'starfighter',\n", + " 'pilots': ['https://swapi.dev/api/people/10/',\n", + " 'https://swapi.dev/api/people/79/'],\n", + " 'films': ['https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-20T20:38:05.031000Z',\n", + " 'edited': '2014-12-20T21:23:49.959000Z',\n", + " 'url': 'https://swapi.dev/api/starships/74/'},\n", + " {'name': 'V-wing',\n", + " 'model': 'Alpha-3 Nimbus-class V-wing starfighter',\n", + " 'manufacturer': 'Kuat Systems Engineering',\n", + " 'cost_in_credits': '102500',\n", + " 'length': '7.9',\n", + " 'max_atmosphering_speed': '1050',\n", + " 'crew': '1',\n", + " 'passengers': '0',\n", + " 'cargo_capacity': '60',\n", + " 'consumables': '15 hours',\n", + " 'hyperdrive_rating': '1.0',\n", + " 'MGLT': 'unknown',\n", + " 'starship_class': 'starfighter',\n", + " 'pilots': [],\n", + " 'films': ['https://swapi.dev/api/films/6/'],\n", + " 'created': '2014-12-20T20:43:04.349000Z',\n", + " 'edited': '2014-12-20T21:23:49.961000Z',\n", + " 'url': 'https://swapi.dev/api/starships/75/'}]\n" + ] + } + ], + "source": [ + "url = 'https://swapi.dev/api/starships?page=1'\n", + "results_data = []\n", + "while url:\n", + " page_content_dict = requests.get(url).json()\n", + " results_data.extend(page_content_dict[\"results\"])\n", + " url = page_content_dict[\"next\"]\n", + " print(url)\n", + "pp(results_data)" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['CR90 corvette',\n", + " 'Imperial I-class Star Destroyer',\n", + " 'Sentinel-class landing craft',\n", + " 'DS-1 Orbital Battle Station',\n", + " 'YT-1300 light freighter',\n", + " 'BTL Y-wing',\n", + " 'T-65 X-wing',\n", + " 'Twin Ion Engine Advanced x1',\n", + " 'Executor-class star dreadnought',\n", + " 'GR-75 medium transport',\n", + " 'Firespray-31-class patrol and attack',\n", + " 'Lambda-class T-4a shuttle',\n", + " 'EF76 Nebulon-B escort frigate',\n", + " 'MC80 Liberty type Star Cruiser',\n", + " 'RZ-1 A-wing Interceptor',\n", + " 'A/SF-01 B-wing starfighter',\n", + " 'Consular-class cruiser',\n", + " 'Lucrehulk-class Droid Control Ship',\n", + " 'N-1 starfighter',\n", + " 'J-type 327 Nubian royal starship',\n", + " 'Star Courier',\n", + " 'J-type diplomatic barge',\n", + " 'Botajef AA-9 Freighter-Liner',\n", + " 'Delta-7 Aethersprite-class interceptor',\n", + " 'H-type Nubian yacht',\n", + " 'Acclamator I-class assault ship',\n", + " 'Punworcca 116-class interstellar sloop',\n", + " 'Providence-class carrier/destroyer',\n", + " 'Theta-class T-2c shuttle',\n", + " 'Senator-class Star Destroyer',\n", + " 'J-type star skiff',\n", + " 'Eta-2 Actis-class light interceptor',\n", + " 'Aggressive Reconnaissance-170 starfighte',\n", + " 'Munificent-class star frigate',\n", + " 'Belbullab-22 starfighter',\n", + " 'Alpha-3 Nimbus-class V-wing starfighter']\n" + ] + } + ], + "source": [ + "#Write a function that returns all of the models of starships\n", + "def get_models():\n", + " model_list=[item['model'] for item in results_data]\n", + " return model_list\n", + " \n", + "pp(get_models())" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ship that can carry most cargo 'Death Star'\n" + ] + } + ], + "source": [ + "#Write a function that finds the ship that can carry the most cargo\n", + "def get_most_cargo():\n", + " cargo_dict={}\n", + " #get ship name and cargo_capacity in a dictionary\n", + " cargo_dict={item['name']:int(item['cargo_capacity']) for item in results_data if (item['cargo_capacity'].isnumeric())}\n", + " # get max cargo capacity\n", + " max_cargo = max(cargo_dict.values())\n", + " # cargo_dict=dict(sorted(cargo_dict.items(), key=lambda kv:(kv[1], kv[0]),reverse=True)) \n", + " #get ship name for the max cargo\n", + " ship_name=[key for key in cargo_dict if cargo_dict[key]==max_cargo]\n", + " return ship_name\n", + " \n", + "print(\"Ship that can carry most cargo '{0}'\".format(get_most_cargo()[0]))" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There are '279,144' crew members and '38000' passengers in 'Executor'\n" + ] + } + ], + "source": [ + "#Write a function that fings of crew and passengers on a given starship\n", + "def find_crew_passenger(starship):\n", + "\n", + " ship={item['crew']:item['passengers'] for item in results_data if item['name']==starship}\n", + " return list(map(list,ship.items()))\n", + "\n", + "ship_name=input(\"Enter the ship name: \")\n", + "result=find_crew_passenger(ship_name)\n", + "print(f\"There are '{result[0][0]}' crew members and '{result[0][1]}' passengers in '{ship_name}'\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ship that can carry most cargo 'Death Star'\n" + ] + } + ], + "source": [ + "#Write a function to find the most expensive starship\n", + "def expensive_starship():\n", + " costly_ship={}\n", + " #get ship name and cost in a dictionary key value pair\n", + " costly_ship={item['name']:int(item['cost_in_credits']) for item in results_data if (item['cost_in_credits'].isnumeric())}\n", + " max_exp = max(costly_ship.values())\n", + " #costly_ship=dict(sorted(costly_ship.items(), key=lambda kv:(kv[1], kv[0]),reverse=True)) \n", + " ship_name=[key for key in costly_ship if costly_ship[key]==max_exp]\n", + " return ship_name\n", + "\n", + "\n", + "expensive_starship() \n", + "print(\"Ship that can carry most cargo '{0}'\".format(expensive_starship()[0]))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Starship that are less than 36000 are ['Solar Sailer']\n" + ] + } + ], + "source": [ + "#Write a function to find all of the starships that are less than a given price\n", + "def starship_lessthan_price(price):\n", + " ship_name=[item['name'] for item in results_data if item['cost_in_credits'].isnumeric() and (int(item['cost_in_credits']) < price)]\n", + " return ship_name\n", + "\n", + "ship_price=int(input(\"Enter ship price:\"))\n", + "print(f\"Starship that are less than {ship_price} are\",starship_lessthan_price(ship_price))" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "starships that have appeared in 3 number of films are ['CR90 corvette', 'Star Destroyer', 'Millennium Falcon', 'Y-wing', 'X-wing', 'Droid control ship']\n" + ] + } + ], + "source": [ + "#Write a function to find the starships that have appeared in a given number of films\n", + "def starship_films(num):\n", + " ship_name=[item['name'] for item in results_data if len(item['films']) == num]\n", + " return ship_name\n", + "\n", + "film_num=int(input(\"Enter number of films:\"))\n", + "print(f\"starships that have appeared in {film_num} number of films are\",starship_films(3))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The shortest ship is 'Jedi Interceptor' and 17.95 feet and the longest ship is 'Death Star' and 393700.8 feet\n" + ] + } + ], + "source": [ + "#Write a function that finds the shortest and longest ship. Return should be the names of the ship in addition to the numeric values. \n", + "# Convert values into feet.\n", + "def ship_length():\n", + " ship={}\n", + " #get the name of ship and length in float (also replaced , in the length)\n", + " ship={item['name']:float((item['length'].replace(',',''))) for item in results_data}\n", + " short = min(ship.values())\n", + " long = max(ship.values())\n", + " #get short ship name\n", + " ship_name_short=[key for key in ship if ship[key]==short]\n", + " #get long ship name\n", + " ship_name_long=[key for key in ship if ship[key]==long]\n", + " return ship_name_short,round(short*3.28084,2),ship_name_long,round(long*3.28084,2)\n", + "\n", + "result=ship_length()\n", + "print(f\"The shortest ship is '{result[0][0]}' and {result[1]} feet and the longest ship is '{result[2][0]}' and {result[3]} feet\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('Naboo star skiff', 'J-type star skiff', '3')\n" + ] + } + ], + "source": [ + "# Create a function for finding the cargo capacity which is 'unknown' and the names starts with 'Naboo'and return a list with their name,model and pilots.\n", + "def cargo():\n", + " for item in results_data:\n", + " if item['cargo_capacity'] =='unknown' and item['name'].startswith(\"Naboo\"):\n", + " ship_name=item['name']\n", + " model=item['model']\n", + " pilots=item['crew']\n", + " return ship_name,model,pilots\n", + "\n", + "print(cargo())" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ships with 0 passengers : ['Y-wing', 'X-wing', 'TIE Advanced x1', 'A-wing', 'B-wing', 'Naboo fighter', 'Jedi starfighter', 'Jedi Interceptor', 'arc-170', 'Belbullab-22 starfighter', 'V-wing']\n" + ] + } + ], + "source": [ + "#Write a function to find the starship_class with no passengers(0) and return in a list.\n", + "def ship_with_no_passenger():\n", + " ship=[item['name'] for item in results_data if item['passengers']=='0' ]\n", + " return ship\n", + "\n", + "print(\"Ships with 0 passengers are: \",ship_with_no_passenger()) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Find length and crew with minimum 1 pilots and 1 films\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.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]" + }, + "orig_nbformat": 4, + "vscode": { + "interpreter": { + "hash": "fc8b46890068e2a6de32ffa038f77616ac3974d41ce3c2c3a4261acff02db9ff" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}