[Solved] Expand Python regex to list of all possible strings [closed]

You could use Exrex. Install with pip install exrex. Then execute in terminal: exrex ‘Good (Morning|afternoon|evening) my (friends|family|brothers|sisters)\. hope you like (apple|orange|grape) juice\.’ Make sure not to forget the backslashes \ before the dots ., as dots are a special character inside regexes. This will return: Good Morning my friends. hope you like apple juice. … Read more

[Solved] User-Defined Functions and Learning to Think Like a Computer Scientist with Python [closed]

Add printTwice(‘bruce’) on a new line after the function, with no indentation like so: def printTwice(bruce): print(‘bruce’) print(‘bruce’) printTwice(‘bruce’) This line will call your printTwice function, passing the value ‘bruce’ to the variable bruce, which is not used. 1 solved User-Defined Functions and Learning to Think Like a Computer Scientist with Python [closed]

[Solved] Restarting code in Python 3.1 [closed]

There are many ways, but this seems to be the shortest path: Answer2 = “Yes” while Answer2 == “Yes”: … Answer2 = input(“Do you want to restart? (Yes/No): “) Typically you might want to .lower ().strip () Answer2 too. 4 solved Restarting code in Python 3.1 [closed]

[Solved] Is it possible to read a .py (python source code) as a file and display its class name, class methods and variables as output….? [closed]

Is it possible to read a .py (python source code) as a file and display its class name, class methods and variables as output….? [closed] solved Is it possible to read a .py (python source code) as a file and display its class name, class methods and variables as output….? [closed]

[Solved] Python count list and types [closed]

newlist = [] for sublist in yourlist: already_in_list = False for index, newsublist in enumerate(newlist): if sublist == newsublist[:-1]: newlist[index][2] += 1 already_in_list = True if not already_in_list: newlist.append(sublist+[1]) – >>>newlist [[‘personA’, ‘banana’, 1], [‘personB’, ‘banana’, 2], [‘personA’, ‘grape’, 1], [‘personA’, ‘lemon’, 2]] solved Python count list and types [closed]

[Solved] Automate the Boring Stuff: Phone number and email extractor [closed]

phoneRegex = re.compile(r”'( (\+)? (\s)? (91)? (\s)? (\d{5}) (\s)? (\d{5}) )”’, re.VERBOSE) You are finding the capture groups and joining them in phoneNum now the capture groups (\+),(\s),(91),(\s),(\d{5}),(\s), and (\d{5}) together make up a phone number. and the large capture group ( (\+)? (\s)? (91)? (\s)? (\d{5}) (\s)? (\d{5}) ) also captures the phone number. … Read more

[Solved] Getting TypeError: ‘int’ object is not subscriptable [closed]

I suspect that’s what you’re looking for: def hourglassSum(): arr = [] for i in range(0,6): arr1=map(int,input().split()) arr.append(list(arr1)) sum=[] for i in range(len(arr)-2): for j in range(min(len(arr[i]), len(arr[i+1]), len(arr[i+2]))-2): sum.append(arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2]) maxi=max(sum) print(maxi) Two notes: (1) you want to persist each iteration of the first loop, what you were doing was just overwriting your variable with … Read more

[Solved] How can I create a list from a to z, and A to Z [duplicate]

You can use the string module, with string.ascii_uppercase and string.ascii_lowercase. If you type: import string string.ascii_uppercase You get: ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’ If you type: string.ascii_lowercase You’ll get the same result, but in lowercase. To solve your problem you can do: import string upper_case = list(string.ascii_uppercase) lower_case = list(string.ascii_lowercase) upper_case and lower_case will be both lists ranging from … Read more