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

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. In … Read more

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

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 my_list): … Read more

[Solved] A Random Wikipedia Article Generator

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 solved A Random Wikipedia Article Generator

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

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 solved Convert Timestamp(Nanoseconds format) to datetime [closed]

[Solved] Function to read csv string

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]

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 solved Parse a nested dictionary [closed]

[Solved] python name error: NameError: name ‘Jewels’ is not defined

You can’t fill a list in this way. Because you start with an empty list, Jewels = [], your attempt to assign to Jewels[0] will result in an IndexError. You can instead use the list.append method jewels = [] for i in range(total_jewels): jewels.append(raw_input(‘Please Enter approx price for Jewel #{}: ‘.format(i))) or a list comprehension … Read more