[Solved] how to make If statement and for loop work for an empty variable

shouldn’t it be something like this? import urllib import argparse def download_web_image(url): IMAGE = url.rsplit(“https://stackoverflow.com/”,1)[1] urllib.urlretrieve(url, IMAGE) parser = argparse.ArgumentParser() parser.add_argument(“num1”) parser.add_argument(“num2”) parser.add_argument(“num3”) args = parser.parse_args() num3 = args.num3 if not num3: for num3 in range(01,50): download_web_image(“https://www.example.com/{num1}/{num2}/{num3}.jpg”.format(num1=args.num1, num2=args.num2, num3=num3)) else: download_web_image(“https://www.example.com/{num1}/{num2}/{num3}.jpg”.format(num1=args.num1, num2=args.num2, num3=num3)) your complete code is (sorry) a mess.. first you have to define … Read more

[Solved] How to avoid ‘1’ when incoming is none

Can you try the following: req_keys = [‘col1’, ‘col2’, ‘col3’, ‘col4’] all_list = [incoming[i] for i in req_keys] all_list = [i for i in all_list if i] print(‘1’.join(all_list)) Example: incoming = {} incoming[‘col1’] = ‘a’ incoming[‘col2’] = None incoming[‘col3’] = ‘c’ incoming[‘col4’] = None Output: a1c Another Example: incoming = {} incoming[‘col1’] = ‘a’ incoming[‘col2’] … Read more

[Solved] Trying to change or interpret the C code to python

So the thing is, Python does not have the same ternary operator. condition?true:false => true if condition else false To implement the line: return(isalpha(ch) ? accvs[ch & 30] : 20) in python, you have to do the following: return (accvs[ord(ch) & 30] if ch.isalpha() else ’20’) solved Trying to change or interpret the C code … Read more

[Solved] Triangular numbers patterns [closed]

I’ll give you a hint since this looks like a h/w assignment. if you check the graphics you posted, for computing (n)th number you’re just adding a new row to the (n-1)th figure at the bottom with n new dots. starting with 1 -> 1 2 -> 1+2 = 3 3 -> 3+3 = 6 … Read more

[Solved] Concatenating items in a list? [duplicate]

count was defined as a string. Is this what you wanted def concat_list(string): count = “” for i in string: count += i return count or you can use def concat_list(string) return ”.join(string) 3 solved Concatenating items in a list? [duplicate]

[Solved] I am tring to make a discord bot that wait for the user message and if three tags are mentioned it give tick reaction

You can use the on_message event to catch every message and do what you like with it. This is better than waiting for a message and executing code as this is faster. The downside is the channel must be hard-coded or use a global variable. Or, you could recreate the whole command in the function … Read more

[Solved] how can I loop to get the list named vlist?

Check this out. List Comprehension import numpy as np import pandas as pd df = pd.read_csv(‘census.csv’) data = [‘SUMLEV’,’STNAME’, ‘CTYNAME’, ‘CENSUS2010POP’] df=df[data] adf = df[df[‘SUMLEV’]==50] adf.set_index(‘STNAME’, inplace=True) states = np.array(adf.index.unique()) vlist=[adf.loc[states[i]][‘CENSUS2010POP’].sort_values(ascending =False).head(3).sum() for i in range(0,7)] 3 solved how can I loop to get the list named vlist?

[Solved] Variable that represents all numbers? [closed]

In Python 3.2 and higher, representing a container with all integers from 1 to a million is correctly done with range: >>> positive_nums_to_1M = range(1, 1000001) >>> 1 in positive_nums_to_1M True >>> 1000000 in positive_nums_to_1M True >>> 0 in positive_nums_to_1M False It’s extremely efficient; the numbers in the range aren’t actually generated, instead the membership … Read more

[Solved] Python. Issue with my interactive story [closed]

from collections import OrderedDict cars = OrderedDict([(1, ‘Camaro’), (2, ‘SS Sedan’), (3, ‘M3 Sedan’), (4, ‘GLE CoupĂ©’)]) print(‘Help Rick P. choose a car to drive.\n’) print(‘\n’.join([str(key) + ‘ ‘ + val for key, val in cars.items()]) + ‘\n’) def choice_car(invalid = False): if invalid: choice = int(input(‘Invalid car. Try again…\n’)) else: choice = int(input(‘Input the … Read more