Python中嵌套列表的排列

如何解决Python中嵌套列表的排列

想象一个列表列表,像这样:

const discord = require('discord.js'); require('dotenv').config(); const client = new discord.Client(); client.login(process.env.BOT_TOKEN); const ms = require('ms'); const prefix = '-'; const fs = require('fs'); client.commands = new discord.Collection(); const commandFiles = fs.readdirsync('./commands/').filter(file => file.endsWith('.js')) for(const file of commandFiles){ const command = require(`./commands/${file}`); client.commands.set(command.name,command); } client.once('ready',() => { console.log('Dahj is online!'); }); client.on('message',async message =>{ if(message.author.bot) return; if(message.content.toLowerCase() === '?listen') { message.channel.send('bot is collecting messages Now...'); let filter = m => !m.author.bot; let collector = new discord.MessageCollector(message.channel,filter); let destination = client.channels.get('767508773966315550'); collector.on('collect',(m,col) => { console.log("Collected message: " + m.content); if(destination) { if(m.content.toLowerCase() === '?stop' && (message.author.id === m.author.id)) { console.log("Stopping collector."); collector.stop(); } else { let embed = new discord.RichEmbed() .setTitle("New Message") .setDescription(m.content) .setTimestamp() .setAuthor(m.author.tag,m.author.displayAvatarURL) .setColor('#FFAB32') destination.send(embed); } } }); collector.on('end',collected => { console.log("Messages collected: " + collected.size); }); } if(message.content.toLowerCase() === '?listen2') { message.channel.send("Enter your name"); let filter = m => m.author.id === message.author.id; try { let msg = await message.channel.awaitMessages(filter,{ maxMatches: 1,time: '10000',errors: ['time'] }); message.channel.send("Your name " + msg.first().content); } catch(ex) { message.channel.send("You did not specify a name on time."); } } }); My error is: (node:15556) UnhandledPromiseRejectionWarning: ReferenceError: discord is not defined at Client.<anonymous> (C:\Users\malibukid71\Documents\Dahj2\main.js:34:25) at Client.emit (events.js:315:20) at MessageCreateAction.handle (C:\Users\malibukid71\Documents\Dahj2\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) at Object.module.exports [as MESSAGE_CREATE] (C:\Users\malibukid71\Documents\Dahj2\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (C:\Users\malibukid71\Documents\Dahj2\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31) at WebSocketShard.onPacket (C:\Users\malibukid71\Documents\Dahj2\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22) at WebSocketShard.onMessage (C:\Users\malibukid71\Documents\Dahj2\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10) at WebSocket.onMessage (C:\Users\malibukid71\Documents\Dahj2\node_modules\ws\lib\event-target.js:125:16) at WebSocket.emit (events.js:315:20) at Receiver.receiverOnMessage (C:\Users\malibukid71\Documents\Dahj2\node_modules\ws\lib\websocket.js:797:20) (Use `node --trace-warnings ...` to show where the warning was created) (node:15556) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:15556) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

除了更长。我需要一个脚本为任意长度的列表生成排列,该列表包含少量单词集,也包含任意长度。

因此,在这种情况下:

import platform
from os import getcwd
from selenium import webdriver

if (platform.system() == 'Windows'):
driver = webdriver.PhantomJS(executable_path=getcwd() + "\phantomjs")

if (platform.system() == 'Darwin'):
driver = webdriver.PhantomJS(executable_path=getcwd() + "/phantomjs")

我无法使用itertools进行管理。有什么建议吗?

解决方法

从itertools中尝试permutations()

from itertools import permutations
x=[['foo','bar'],['baz'],['xyz']]
for y in permutations(x):
  print(y)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?