AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[list](coding)

Martin Hope
Logan Slattery
Asked: 2025-03-23 04:50:19 +0800 CST

如何批量创建、访问和修改灵活列表

  • 5

我有一个批处理文件,用于检查是否存在先前编译的 exe 文件。如果不存在,它将重新编译,否则它将检查自创建 exe 文件以来是否有任何文件被修改过。如果发现修改过的文件,它将重新编译。然后它检查目录,跟踪文件内容的名称和时间戳。

我想知道如何做到这一点,这样我就不必手动列出:

file[0]=
file[1]=
file[2]=
etc.

现在我已经有了一个可以随时修改的列表,并且可以工作,但它的修改方式如下:

set SOURCES=!SOURCES! "%%F"

我的时间戳列表如下:

set LIST=!LIST! %FILE_TIMESTAMP_FORMAT%

我已经检查了很多来源,没有一个是动态的,或者对我来说根本不起作用。还有谁知道为什么格式无法编辑echo。

@echo off
setlocal enabledelayedexpansion

cd /d "C:\Users\ealos\OneDrive\Desktop\C++ Project"

echo Current directory: %CD%

set SOURCES=
set FILES_CHANGED=false
set LIST=

rem Check if cppgame.exe exists and get its timestamp
if exist cppgame.exe (
    for %%F in (cppgame.exe) do (
        set EXE_TIMESTAMP=%%~tF
    )
    echo cppgame.exe last modified: !EXE_TIMESTAMP!
    rem Convert cppgame.exe timestamp to comparable format
    set EXE_TIMESTAMP_FORMAT=!EXE_TIMESTAMP:~6,4!!EXE_TIMESTAMP:~0,2!!EXE_TIMESTAMP:~3,2!!EXE_TIMESTAMP:~11,2!!EXE_TIMESTAMP:~14,2!
    echo EXE Timestamp Format: !EXE_TIMESTAMP_FORMAT!
) else (
    echo cppgame.exe does not exist or was just created.
    set FILES_CHANGED=true
)

rem Loop through all .cpp files and check if any are newer than cppgame.exe
for %%F in (*.cpp) do (
    echo -----------
    rem Add the .cpp file to the SOURCES variable for compilation
    set SOURCES=!SOURCES! "%%F"
    
    rem Get the timestamp of the current .cpp file
    set FILE_TIMESTAMP=%%~tF
    rem Convert .cpp file timestamp to comparable format
    set FILE_TIMESTAMP_FORMAT=!FILE_TIMESTAMP:~6,4!!FILE_TIMESTAMP:~0,2!!FILE_TIMESTAMP:~3,2!!FILE_TIMESTAMP:~11,2!!FILE_TIMESTAMP:~14,2!
    
    echo Checking: %%F (Modified: !FILE_TIMESTAMP!)
    echo File Timestamp Format: (!FILE_TIMESTAMP_FORMAT!)
    
    rem Add the formatted timestamp to the LIST for comparison
    set LIST=!LIST! "%FILE_TIMESTAMP_FORMAT%"
    echo list: %LIST%
)

rem Now compare each timestamp in LIST with cppgame.exe's timestamp
echo %LIST%
for /f "tokens=1, delims==" %%a in (%LIST%) do (
    echo Comparing: %%a with !EXE_TIMESTAMP_FORMAT!
    if %%a GTR %EXE_TIMESTAMP_FORMAT% (
        set FILES_CHANGED=true
        echo File has changed, setting FILES_CHANGED=true
    )
    echo EXE Timestamp Format: !EXE_TIMESTAMP_FORMAT!
    echo File Timestamp Format: %%a
)

rem If no files have changed, just run the existing executable
if "!FILES_CHANGED!"=="false" (
    echo No files changed, running existing executable...
    cppgame.exe
    pause
    exit /b
)

rem If no .cpp files are found, exit
if "%SOURCES%"=="" (
    echo No .cpp files found in the directory!
    pause
    exit /b
)

rem Compile all .cpp files into a single executable (cppgame.exe)
echo Compiling...
g++ %SOURCES% -o cppgame.exe

rem Check if compilation was successful
if %ERRORLEVEL% NEQ 0 (
    echo Compilation failed!
    pause
    exit /b
)

rem Run the compiled executable
echo Running cppgame...
cppgame.exe

rem Pause to keep the console open after execution
pause
list
  • 1 个回答
  • 45 Views
Martin Hope
Grace64
Asked: 2025-03-09 16:11:02 +0800 CST

在 Dart 中删除另一个键后自动分配 Map<int, String> 键

  • 6

我是编程新手,正在学习 Dart 课程。我正在尝试构建一个待办事项列表控制台程序,并使用地图作为待办事项列表。我正在尝试弄清楚如何自动分配键,以便当我删除一个条目时,后面的键会相应更改(例如,删除第二个条目并将前一个第三个条目的键更改为 2,依此类推)。

我该如何处理呢?

这是我迄今为止添加条目的代码:

int taskId = toDoList.length;

case 'c' :  
      userInput = null;
      print('Enter name of new adventure');
      print('');
        if (taskId >= toDoList.length) {
          ++taskId;
        } 
        String task = stdin.readLineSync()!;
        toDoList[taskId] = task;
      print('Quest added!');
              for (final allPrint in mainMenu.entries) {
                print('${allPrint.key}: ${allPrint.value}');
              } ;

这是我删除条目的代码:

    case 'b' :  
      userInput = null;
          if (toDoList.length < 1) {
      print('No quests available to complete!');
          for (final allPrint in mainMenu.entries) {
          print('${allPrint.key}: ${allPrint.value}');
          };
      } else{
          print('Which good fortune have you brought from your adventures?');
          print('Which task have you completed?');
          print('');
            for (final allPrint in toDoList.entries) { 
                print('${allPrint.key}: ${allPrint.value}');
            }
          print('');
          print('');
            int? idDelete = int.tryParse(stdin.readLineSync() ?? '');
              if (toDoList.containsKey(idDelete)) {
                  toDoList.remove(idDelete);
                  print('Good Job!');
              for (final allPrint in mainMenu.entries) {
                print('${allPrint.key}: ${allPrint.value}');
              } ;
            }
        }
list
  • 1 个回答
  • 25 Views
Martin Hope
MikeB2019x
Asked: 2025-02-26 03:49:21 +0800 CST

将列表转换为字符串

  • 7

我正在使用 Polars,我有一个数据集,其中有一列是字符串列表。要查看它是什么样子:

import pandas as pd

list_of_lists = [['base', 'base.current base', 'base.current base.inventories - total', 'ABCD']
                  , ['base', 'base.current base', 'base.current base.inventories - total','ABCD']
                  , ['base', 'base.current base', 'base.current base.inventories - total', 'ABCD']
                  , ['base', 'base.current base', 'base.current base.inventories - total', 'ABCD']]

pd_df = pd.DataFrame({'lol': list_of_lists})

给出:

    lol
0   ['base', 'base.current base', 'base.current base.inventories - total', 'ABCD']
1   ['base', 'base.current base', 'base.current base.inventories - total', 'ABCD']
2   ['base', 'base.current base', 'base.current base.inventories - total', 'ABCD']
3   ['base', 'base.current base', 'base.current base.inventories - total', 'ABCD']

我想对每个列表进行哈希处理。我想将每个列表转换为字符串,然后对其进行哈希处理。我可以用 Pandas 做到这一点

pd_df = pd.DataFrame({'lol': list_of_lists}).astype({'lol':str})
pl_df_1 = pl.DataFrame(pd_df)
pl_df_1.with_columns(pl.col('lol')
                    .hash(seed=140)
                    .name.suffix('_hashed')
                    )

给出:

               lol                  lol_hashed
               str                   u64
"['base', 'base.current base', …    14283628883798345624
"['base', 'base.current base', …    14283628883798345624
"['base', 'base.current base', …    14283628883798345624
"['base', 'base.current base', …    14283628883798345624

但如果我尝试在 Polars 中执行类似操作,我会收到错误:

pl_df_2 = pl.DataFrame({'lol': list_of_lists})
pl_df_2.with_columns(pl.col('lol') # <== can insert .cast(pl.String) here still get error
                    .hash(seed=140)
                    .name.suffix('_hashed')
                    )

给出:

# PanicException: Hashing a list with a non-numeric inner type not supported. 
#   Got dtype: List(String)

我更愿意使用 Polars 库,那么是否可以将列表列转换为字符串,或者在 Polars 中是否有更好的方法来实现相同的结果?

更新:

根据接受的答案,我进行了进一步的实验。

list_of_lists = [
                 ['base', 'base.current base', 'base.current base.inventories - total', 'ABCD'], 
                 ['base', 'base.current base', 'base.current base.inventories - total', 'DEFG'], 
                 ['base', 'base.current base', 'base.current base.inventories - total', 'ABCD'], 
                 ['base', 'base.current base', 'base.current base.inventories - total', 'HIJK'], 
                 '(bobbyJoe460)',
                 'bobby, Joe (xx866e)',
                 137642039575
                 ]

pl_df_1 = pl.DataFrame({'lol': list_of_lists}, strict=False)  # <==== allow mixed types in column
pl_df_1.with_columns(pl.col('lol')
                     .cast(pl.Categorical)  # <==== cast to Categorical
                     .hash(seed=140)
                     .name.suffix('_hashed')
                     )

给出:

                 lol.               lol_hashed
                 str                    u64
"["base", "base.current base", …    11231070086490249882
"["base", "base.current base", …    6519339301964281776
"["base", "base.current base", …    11231070086490249882
"["base", "base.current base", …    14549859594875138034
"(bobbyJoe460)"                     1954884316252525743
"bobby, Joe (xx866e)"               4241414284122449899
"137642039575"                      6383308039250228053
list
  • 1 个回答
  • 32 Views
Martin Hope
Ralf_Reddings
Asked: 2025-02-09 08:30:52 +0800 CST

如何获取可变数组的字符串?

  • 5

这件事一直困扰着我,几周前我想出了一个解决办法,但我忘了:

$l=[System.Collections.Generic.List[string[]]]::new()
$l.Add("one", "two", "three")
$l.ToString()                                                  #returns ---> System.String[]
"$l"                                                           #returns ---> System.String[]           
 [string]$l                                                  #returns ---> System.String[]       
 $l -join "`n"                                              #returns ---> System.String[]       

我期望类似以下内容或由$ofs变量指定的其他内容:

one
two
three

我在 pwsh 7.4

list
  • 2 个回答
  • 38 Views
Martin Hope
M1ctl4nt3cutl1
Asked: 2024-11-19 03:45:20 +0800 CST

我怎样才能从 Common Lisp 列表中删除“。”?

  • 6

我是 lisp 新手,在使用“ ”时遇到了困难append。我必须重新排序列表,并将输入列表的第一个元素作为输出列表的最后一个元素。我尝试使用“ append”和“ nconc”,每次我都能得到我想要的列表,但.在最后一个元素之前有一个“ ”。这个点是什么意思?有什么方法可以避免出现这个符号吗?

多谢!

 (nconc (rest l)(first l)) >> (B C D E . A)

 (append (rest l) (first l)) >> (B C D E . A)
list
  • 1 个回答
  • 17 Views
Martin Hope
lanf
Asked: 2024-10-11 08:11:26 +0800 CST

在 Haskell 中,获取列表中的元素,包括满足某些谓词的第一个值

  • 5

给定一个谓词p,takeWhile p xs给出满足的元素的最长前缀p。如何获取包含满足的元素的最短前缀p?

编辑:对于那些反对我的问题的人,如果你们能留下评论解释一下你们不喜欢什么,我会很高兴。

list
  • 2 个回答
  • 49 Views
Martin Hope
Sandman42
Asked: 2024-09-26 22:18:22 +0800 CST

Dart List 错误类“List”没有未命名的构造函数[重复]

  • 5
此问题这里已有答案:
启用空安全时,默认的“List”构造函数不可用。尝试使用列表文字“List.filled”或“List.generate” (4 个答案)
昨天休息。

我正在尝试通过以下方式创建服务器列表:

class Server {
  final String country;
  final String ip;
  final String username;
  final String password;

  const Server(
      {required this.country, required this.ip, required this.username, required this.password});

  static List<Server> allServers() {
    var myServers = new List<Server>();

    myServers.add(const Server(
        country: "Italy"
        ip: "1.2.3.4.example.com",
        username: "user1",
        password: "password1"
    ));
    myServers.add(const Server(
        country: "United States",
        ip: "5.6.7.8.example.com",
        username: "user2",
        password: "password2"
    ));
    return myServers;
  }
}

我收到错误“类‘List’没有未命名的构造函数”

我该如何修复它?

提前致谢

list
  • 1 个回答
  • 21 Views
Martin Hope
kesarling
Asked: 2024-09-25 05:31:48 +0800 CST

我如何重载 haskell 中的某个运算符以在两侧采用不同类型?

  • 5

口粮:

class Foo s where
    myCons :: Char -> s -> s
    myCons c xs = <my definition of however I wish to interpret this>

instance (Eq, Show) Foo where
    (:) x y = x `myCons` y

错误:

Pattern bindings (except simple variables) not allowed in instance declaration:
      (:) x y = x `myCons` y

我做错什么了?

我想要做的事情:

fooFromList :: [Int] -> Foo
fooFromList [] = Foo []
fooFromList (x:xs) = let x' = (convertDigitToChar x) in x':(fooFromList xs)
list
  • 2 个回答
  • 54 Views
Martin Hope
Asian AMP
Asked: 2024-05-15 04:40:56 +0800 CST

使用 shell 列出目录并使用 groovy 迭代

  • 4

有人可以帮忙提供解决方案吗?

我尝试使用 groovy 文件中的 shell 脚本列出某个位置(/root/var/)下的文件夹。根据检索到的文件夹数量,我必须使用 groovy 中的 For 循环单独迭代文件夹名称(而不是文件夹内的文件)。

下面是我的 groovy 文件中的 shell 脚本。

def 文件夹位置 = "/root/var/*/" List l = sh(script: "ls -d ${folderlocation}", returnStdout: true).trim().split('\n')

for(l中的fldr){ 打印(l) }

我看到 l 的输出是绝对路径而不是文件夹名称。

例如:/root/var/ 包含 lib 作为子目录。

我看到 l 打印为 /root/var/lib/

我期望 l 仅包含 lib 而不是绝对路径或任何其他文件夹名称(如果有)。

有人可以帮助我吗?

list
  • 1 个回答
  • 8 Views
Martin Hope
David
Asked: 2024-04-20 14:52:58 +0800 CST

从详细信息视图返回时,侧边栏上的所选项目强制返回零(在 iPhone 上)

  • 5

我有一个带有侧边栏和详细信息视图的NavigationSplitView。从侧边栏中选择项目时,详细信息视图会更新以显示所选内容。到目前为止,这一切在 iPhone 和 iPad 上都运行良好。

然而,在 iPhone 上,当返回侧边栏视图选择其他内容时,之前选择的项目将被设置为 nil。

在 iPad 上,它不会将之前选择的项目设置为零,即使您隐藏并显示侧边栏,它仍然会记住之前选择的条目。

我也尝试过 iPhone 模拟器和物理设备。

要重现该问题,请参阅下面的小(完整)代码。在模拟器或物理设备上运行它。从侧边栏中选择一个条目,将显示/更新详细信息以显示所选内容。返回到侧边栏视图,您可以看到大约半秒钟之前选择的项目仍然处于选中状态,然后它被设置为 nil。

返回侧边栏视图时,为什么 iPhone 上的选择会重置为零?

import SwiftUI

struct ContentView: View {
    @State private var selection: String?
    var body: some View {
        NavigationSplitView {
            SidebarView(selection: $selection)
        } detail: {
            DetailView(selection: $selection)
        }
    }
}

struct SidebarView: View {
    @Binding var selection: String?
    let people = ["Finn", "Leia", "Luke", "Rey"]
    var body: some View {
        List(people, id: \.self, selection: $selection) { person in
            Text(person)
        }
        Text("selection = \(String(describing: selection))")
    }
}

struct DetailView: View {
    @Binding var selection: String?
    var body: some View {
        Text("selectedItem = \(String(describing: selection))")
    }
}

#Preview {
    ContentView()
}

请参阅下面的 GIF。注意屏幕底部的侧边栏。返回到侧边栏时,您会看到它仍然显示先前选择的项目,时间很短,大约半秒左右。然后它被清除为零。

显示问题的示例

list
  • 1 个回答
  • 14 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve