我的代码有问题。我有一系列的字符串。例如我做了这个:
var a = 12345678
Run Code Online (Sandbox Code Playgroud)
我想将这些字符串分割成一个数组,这样它就会产生如下所示的结果:
[12,23,34,45,56,67,78]
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这段代码:
var newNum = a.toString().match(/.{1,2}/g)
Run Code Online (Sandbox Code Playgroud)
它返回这个结果而不是我想要的结果
[12,34,56,78]
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗?提前致谢。
我正在尝试使用 Python 从 CSV 源到 PostgreSQL 数据库的新 ETL 过程。
我已经做好了目的地的桌子。但是,我在数据库的表中有 create_at 列,并以 CURRENT_DATE 作为默认值。另一方面,我的 CSV 文件上没有 create_at 列。
数据库中的 WP_SALES 表包含:
id (int) PK
order_date (timestamp)
order_status (character varying)
customer_id (smallint)
product (character varying)
product_category (character varying)
quantity (smallint)
total_price (money)
create_at (date) DEFAULT CURRENT_DATE
Run Code Online (Sandbox Code Playgroud)
在 CSV 上,它包括:
id
order_date
order_status
customer_id
product
product_category
quantity
total_price
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的代码:
import psycopg2
conn = psycopg2.connect ("host=localhost dbname=postgres user=postgres port=5432")
cur = conn.cursor()
with open('[Technical Test - Data Engineer] Sale Report - wp.csv', 'r') …Run Code Online (Sandbox Code Playgroud) 我想将值添加到arraylist到arraylist中找到的下一个空索引。
假设我有长度为5的ArrayList。ArrayList的索引0-2已经填充。我想向索引3添加另一个值。我有这段代码,但是它不起作用(将索引返回到绑定异常之外)。
ArrayList<String> nameList = new ArrayList<String>(5);
nameList.add(0,"a");
nameList.add(1,"b");
nameList.add(2,"c");
for (int i = 0; i < nameList.size(); i++) {
while (!nameList.get(i).isEmpty()) i++;
nameList.add(0,"d");
}
System.out.println(nameList);
Run Code Online (Sandbox Code Playgroud)
有什么办法可以做到这一点?
我正在尝试在这3个变量(不是范围,而是仅在这3个值之间)之间进行随机化,并将其存储到新变量中。
int randomProductDiscount() {
int disc1 = 25;
int disc2 = 35;
int disc3 = 50;
int productDiscount = (random between disc1 or disc2 or disc3);
return productDiscount;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。
我在这个特殊问题上有困难。
我被要求找到一个严格比输入数组少一个元素的组合子集。例如从数组:
var num = [1,2,3,4,5]
Run Code Online (Sandbox Code Playgroud)
找到以下组合:
[1,2,3,4]
[2,3,4,5]
[1,2,4,5]
[1,2,3,5]
[1,3,4,5]
Run Code Online (Sandbox Code Playgroud)
从这个数组:
var num = [2,4,6]
Run Code Online (Sandbox Code Playgroud)
找到以下组合:
[2,4]
[2,6]
[4,6]
Run Code Online (Sandbox Code Playgroud)
我已经尝试过此代码,但是它不是动态的,因为我必须打印数组的每个索引:
var num = [1,2,3,4,5];
var n = num.length;
var i, j;
for(i = 0; i < n; i++){
for(j = i + 1; j < n; j++){
console.log(num[i] + ", " + num[j]);
}
}
Run Code Online (Sandbox Code Playgroud)
有什么办法吗?提前致谢。
arrays ×2
java ×2
javascript ×2
arraylist ×1
combinations ×1
etl ×1
function ×1
int ×1
methods ×1
postgresql ×1
psycopg2 ×1
python ×1
random ×1