[Solved] Use a formatted string to separate groups of digits

[ad_1] This is one way to achieve what you are looking to do: number = “12345678910” print( ‘number id {0}.{1}.{2}-{3}’.format( *[number[i:i+3] for i in range(0,len(number), 3)] ) ) #number id 123.456.789-10. There are a few problems with your code. First the first number in the “{0…}” refers to the positional argument in the format() function. … Read more

[Solved] How would I convert a str to an int?

[ad_1] First, use split() to split the input into a list. Then, you need to test isnumeric() on every element of the list, not the whole string. Call int() to convert the list elements to integers. Finally, add the sum to counter, not counter_item. my_list = input(“Input your list.(Numbers)\n”).split() while not all(item.isnumeric() for item in … Read more

[Solved] A Random Wikipedia Article Generator

[ad_1] According to: https://en.wikipedia.org/wiki/Wikipedia:Special:Random The endpoint for a categorized random subject is: https://en.wikipedia.org/wiki/Special:RandomInCategory/ And not: https://en.wikipedia.org/wiki/Special:Random/ So you should change your url to: url = requests.get(f”https://en.wikipedia.org/wiki/Special:RandomInCategory/{topic}”) 1 [ad_2] solved A Random Wikipedia Article Generator

[Solved] Convert Timestamp(Nanoseconds format) to datetime [closed]

[ad_1] You should be using = to assign values and not : You can do like this. import datetime example_timestamp = int(‘1629617204525776950’) timestamp_to_date_time = datetime.datetime.fromtimestamp(example_timestamp/1000000000).strftime(‘%Y-%m-%d %H:%M:%S,%f’) print(timestamp_to_date_time) 2021-08-22 07:26:44,525777 [ad_2] solved Convert Timestamp(Nanoseconds format) to datetime [closed]

[Solved] Function to read csv string

[ad_1] Here’s how to do what you say you want. Your description of the desired “table” output is somewhat vague, so I made my best guess. def get_rows(data): rows = [] for line in data.splitlines(): fields = line.split(‘,’) if not any(field == ‘NULL’ for field in fields): # Not defective row. rows.append(fields) return rows csv_string … Read more

[Solved] Parse a nested dictionary [closed]

[ad_1] ids = [int(row[‘id’]) for row in b[‘cricket’][‘Arts & Entertainment’]] will give you a list of the numbers, [6003760631113, 6003350271605, 6003106646578, 6003252371486, 6003370637135] And for your new edits; ids = [int(row[‘id’]) for row in b[‘cricket’][‘Arts & Entertainment’] + b[‘News, Media & Publications’]] 3 [ad_2] solved Parse a nested dictionary [closed]