Timeline for Shorten dict comprehension with repeated operation
Current License: CC BY-SA 4.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 11, 2020 at 22:02 | history | edited | OverLordGoldDragon | CC BY-SA 4.0 |
added 158 characters in body
|
Oct 11, 2020 at 22:00 | comment | added | GZ0 | @OverLordGoldDragon You can edit it into yours. | |
Oct 11, 2020 at 10:46 | comment | added | OverLordGoldDragon | @GZ0 Nice improvement - can post as answer if you wish, or I'll edit it into mine with credit. | |
Oct 11, 2020 at 7:19 | comment | added | GZ0 |
@MateenUlhaq That creates a tuple, which in this case is not much different from a list. One approach to avoid allocating a new collection is this: {k: v for k, v in (line.split('=') for line in txt)}
|
|
Oct 10, 2020 at 22:51 | comment | added | Mateen Ulhaq |
You could also write (line.split("="),) to avoid allocating a list.
|
|
Oct 10, 2020 at 18:47 | comment | added | OverLordGoldDragon |
@Graipher That's the idea, line is split into a "left' and "right", key and value, so a 'trick' around duplicating line.split .
|
|
Oct 10, 2020 at 13:14 | history | edited | OverLordGoldDragon | CC BY-SA 4.0 |
deleted 100 characters in body
|
Oct 10, 2020 at 13:13 | history | undeleted | OverLordGoldDragon | ||
Oct 10, 2020 at 13:11 | history | deleted | OverLordGoldDragon | via Vote | |
Oct 10, 2020 at 12:47 | history | answered | OverLordGoldDragon | CC BY-SA 4.0 |